0

I'm designing a game, and the game heavily requires the use of color for my maps. I wanted to use gradients to count numerically in hexidecimal (like #000001, #000002, etc, because drawing all of it out would be hard work) , to demarcate hills and such because that's how I designed the system to work. So, while testing this system I realise the default gradient is counting in steps in every colour each, not just from the bottom like I wanted (my aim is from #000000 to #000CCC, so it was adding 1 to both the Green and Blue values instead of just Blue). I discovered the 'Linear RGB' checkbox option and hoped it would do that, but it somehow doesn't. It works sometimes for values like #00CCCC but when I try #0000000 to #000CCC, it stops at #0000CB for no reason, although it does count using only the Blue values. I'm using Flash CS4, not sure if its a problem on my end or smth else. Also, the Flash docs give me no info on what the Linear RGB checkbox does, so if someone could help explain it that would be great too.

1 Answers1

1

Per your requirements, this is an example of computing steps between 0x000000 and 0x000ccc

10-steps

gradient-steps

32-steps:

gradient-steps-32

var startColor:uint = 0x000000;
var endColor:uint = 0x000ccc;
var steps:uint = 10;

var graphics:Graphics = graphics;

for (var i:uint = 0; i < steps; i++)
{
    var r:uint = ((endColor >>> 16 & 0xFF) - (startColor >>> 16 & 0xFF)) * (i / steps);
    var g:uint = ((endColor >>> 8 & 0xFF) - (startColor >>> 8 & 0xFF)) * (i / steps);
    var b:uint = ((endColor & 0xFF) - (startColor & 0xFF)) * (i / steps);

    var stepColor:uint = r << 16 | g << 8 | b;

    graphics.beginFill(stepColor);
    graphics.drawRect(i * 24, 24, 24, 24);
    graphics.endFill();
}

Your issue is likely manipulating RGB values; however, here are docs regarding interpolation methods:

From Adobe Docs flash.display.InterpolationMethod http://livedocs.adobe.com/livecycle/es/sdkHelp/common/langref/flash/display/InterpolationMethod.html

Linear RGB:

Specifies that the linear RGB interpolation method should be used. This means that Flash Player uses an RGB color space based on a linear RGB color model.

RGB

Specifies that the RGB interpolation method should be used. This means that Flash Player uses the exponential sRGB (standard RGB) space when rendering the gradient. The sRGB space is a W3C-endorsed standard that defines a non-linear conversion between red, green, and blue component values and the actual intensity of the visible component color.

For example, consider a simple linear gradient between two colors (with the spreadMethod parameter set to SpreadMethod.REFLECT). The different interpolation methods affect the appearance as follows:

InterpolationMethod.LINEAR_RGB InterpolationMethod.RGB

Jason Sturges
  • 15,855
  • 14
  • 59
  • 80
  • First thanks for the explanation on RGB and the link. I'm afraid to say, but I simply cannot draw this via a programmable method. I tried looking to learn from your program, and there's alot of bitwise functions and such... Look, the solution I want isn't a gradient. I want to be able to count upwards with the blue values eventually spilling to green then red. I want the colour values to act like a regular number. The gradient is simply an effective way of getting from one number to another in a perfectly linear&numerical fashion. Does Flash have an option or a loophole I could use to do that? – Tobe chukwu Anyansi May 30 '12 at 15:26
  • Actually a programmable method would be easier, since it lets me treat the colour value as a uint, but I will not have the precision that Flash provides me to draw with a gradient for a particular area. Or is there some other program that I could use to do this? (Though it maybe hard importing the picture back into Flash) – Tobe chukwu Anyansi May 30 '12 at 15:29