views:

106

answers:

2

i'm having a strange issue with banding between certain colors of a gradient.

to create the gradient, i'm drawing evenly spaced circle wedges from the center to the border, and filling each circle wedge from a bitmap line gradient pixel in a loop.

i'm creating a circle with 3600 wedges, although it doesn't look like it based on the screen shot within the orange color that is produced from gradating from red to yellow numbers. adding a orange number between red and yellow doesn't help. but if i create the circle with only 360 wedges, the gradient banding is much more obvious. 3600 is probably overkill, and doesn't really add more detail over, say, making the circle of 1440 wedges, but i don't know any other way to slightly elevate this banding issue.

any ideas how i can fix this, or what i'm doing wrong? could it be caused by the circleMatrix rotation?

alt text

A: 

I think the banding is being caused by your ratios.

Try this:

graphics.beginGradientFill(GradientType.LINEAR, [nColor, nColor], [1, 1], [0, 255], objMatrix)

Also, should objMatrix actually be circleMatrix?

You can see the difference between [127, 255] and [0, 255] in the LiveDoc's

maclema
the ratios are from the center out. i've updated my code so you can it fully.
TheDarkInI1978
+1  A: 

Edit: Due to precision error some artifact can appear since you have only a range of 255 values to distribute.

To minimize this visual effect you can try to add some blur to your color band, but beware of the join between the left and the right side :

//...

//Assign bitmapData to the leftToRightLine
var leftToRightLineBitmapData:BitmapData = 
                   new BitmapData(leftToRightLine.width,leftToRightLine.height);
leftToRightLineBitmapData.draw(leftToRightLine);

// add some blur filter to the color band
leftToRightLine.filters=[new BlurFilter(2,0, 3)];

// copy the color band on the bitmap but but starting at 1 pixel right to avoid
// the blur on the start
leftToRightLineBitmapData.draw(leftToRightLine, new Matrix(1,0,0,1, 1));

for(var i:int = 1; i < (DEFAULT_BANDING_QUALITY + 1); i++)
{
  //...

Without full code to test, hard to know if i aim in the right direction ;)

  • There is an error in your radian conversion it's i*Math.pi/180 and not /1800, so now you can go to 360 and not 3600
  • why start from 1 and not from 0 ?

  • try to play with the line thickness and use the lineGradientStyle

  • You referer to an objMatrix but create a circleMatrix

Patrick
i've edited my code to show everything. hopefully you can help me figure out the error
TheDarkInI1978
@TheDarkIn1978 Ok i have edited my answer
Patrick
thanks. i was hoping it wouldn't have to come to using a filter, but it does the trick. rather than adding it to the bitmap i just threw a 2px x 2px filter on on the entire sprite. also, i reduced the default banding quality to 720, since it looks identical to 3600, but loads way faster. i'm assuming they looked identical based on this limit you've mentioned? can you offer an explanation on this distribution range limit of 255, and what was actually happening?
TheDarkInI1978