2 Replies Latest reply on Jul 17, 2007 11:01 AM by BishopNeo

    Color  Gradiations

    BishopNeo
      The premise is this, I have a starting color, blue (0x0000ff) and an ending color, red (0xFF0000). I have a 10 block high 'tower'. The tower grows from zero blocks to ten depending on several variables, each higher block is a step in color from blue to red (i.e. block 5 is basically purple). I'm trying to figure out how to determine the color of each block using AS3.

      Yes I could hard code the colors but there is a possibility that the starting and ending colors might change based on other factors and I'm not keen on hardcoding every possible color combination.

      First question, did I describe it clearly?
      Second question, anyone have any thoughts on how to accomplish this?

      _Anthony
        • 1. Re: Color  Gradiations
          Oddsy Level 1
          You can treat the start and end colour as numbers and work it out that way. So suppose you have your blue and red as SolidColor instances you could do something along the lines of:

          var numberOfColors:uint = 10;
          var startColor:SolidColor = new SolidColor(0x0000FF,1);
          var endColor:SolidColor = new SolidColor(0xFF0000,1);

          var colorStepSize:uint = Math.round(Math.abs(startColor.color - endColor.color) / numberOfColors);

          // then you'd get each of your colours like so (I've used a loop but whatever you fancy)
          for (var i:uint = 0; i < numberOfColors; i++)
          {
          var newColor:SolidColod = new SolidColor(startColor.color + (colorStepSize * i), 1);
          // whatever you want to do with your new color
          }


          I've just typed that out here without testing it so don't copy and paste it directly. It should clarify how I'd do it though.
          • 2. Re: Color  Gradiations
            BishopNeo Level 1
            Not 100% what I was looking for but it got me close enough to figure out the rest. Thanks Oddsy! (this is what I get for trying to learn Flex in 3 weeks... brain dump)