5 Replies Latest reply on Jul 5, 2013 6:32 AM by kglad

    Color transform help

    prodigalmaster Level 2

      Hi

       

      I have no experience with the colour transform class but some with the RGB hexidecimal concept.

       

      Let's use a little pseudo code / actionscript hybrid:

       

      In the following example, which doesn't work, I am trying to remove red and green colour and keep blue. How do I do this?

       

        colour = 0xFFFFFF;
        colourTrans.rgb = colour;
                red = 0;
                green = 0;
                blue = 1;
                colourTrans.redMultiplier = red;
                colourTrans.greenMultiplier = green;
                colourTrans.blueMultiplier = blue;
                colour = colourTrans.rgb;
        // colour outputs 0, not the new blue colour
      

       

      Thanks.

        • 1. Re: Color transform help
          kglad Adobe Community Professional & MVP

          use the colormatrixfilter:

           

           

          var matrix:Array;

          var filter:BitmapFilter

           

          function blueF(image:MovieClip):Void{

               matrix=[];

              matrix = matrix.concat([0, 0, 0, 0, 0]); // red

              matrix = matrix.concat([0, 0, 0, 0, 0]); // green

              matrix = matrix.concat([0, 0, 1, 0, 0]); // blue

              matrix = matrix.concat([0, 0, 0, 1, 0]); // alpha

           

              filter = new ColorMatrixFilter(matrix);

              image.filters = [filter];

          }

          • 2. Re: Color transform help
            prodigalmaster Level 2

            Thanks but the example I gave was far more simplified to get my point across saying I don't know how to *get* the value from the colourTrans... the way I am actually doing it is quite complicated and requires the colour multipliers so I can get a sequence of colours:

             

            import flash.geom.ColorTransform;

            import flash.geom.Transform;

            var colourTrans:ColorTransform = new ColorTransform();

            var colourBG:Number = 0x000000;

            var colour:Number = 0xFFFFFF;

            var frequency = 0.3;

            var count = 0;

             

            onEnterFrame = function () {

                      colourTrans.rgb = colour;

                      count += frequency;

                      red = Math.sin(frequency*count);

                      green = Math.sin(frequency*count+2);

                      blue = Math.sin(frequency*count+4);

                      colourTrans.redMultiplier = red;

                      colourTrans.greenMultiplier = green;

                      colourTrans.blueMultiplier = blue;

                      colour = colourTrans.rgb;

                      trace(colour);

            //...

            };

            • 3. Re: Color transform help
              kglad Adobe Community Professional & MVP

              then don't abstract what you're trying to do.  just explain what you're trying to do.

              • 4. Re: Color transform help
                prodigalmaster Level 2

                Basically for each frame (onEnterFrame), return a new colour so that over time the colour turns from red to green to blue to red... like a rainbow... a sequence of colours. The red, green, and blue Math.sin code above uses the correct multipliers I think to do this (the offset is not exactly correct (2 and 4) but good enough...

                 

                again.. all I need is a way to output the colour after the multipliers have altered the inputted colour, each frame.

                 

                Unless there is another way to do this such as with matrixes (which I again have no experience with).

                Thanks.

                 

                edit: and when I mean output a colour I mean store the number for the colour in the 'colour' variable.

                • 5. Re: Color transform help
                  kglad Adobe Community Professional & MVP

                  use:

                   

                   

                  class com.kglad.Color_AS2 {

                   

                      // example usage:

                      /*

                      import com.kglad.Color_AS2;

                      import flash.geom.ColorTransform;

                     

                      Color_AS2.colorChangeF();

                      var ct:ColorTransform = mc.transform.colorTransform;

                     

                      this.onEnterFrame = function(){

                      ct.rgb = Color_AS2.colorF();

                      mc.transform.colorTransform = ct

                      }

                      */

                      static var red:Object = new Object();

                      static var green:Object = new Object();

                      static var blue:Object = new Object();

                   

                      static var colorValueA:Array = [15, 0, 128];

                      static var colorA:Array = [red, green, blue];

                      static var colorChangeA:Array = [1, -1];

                      static var primeA:Array = [3, 5, 7];

                   

                      function Color_AS2() {

                      }

                      static function colorChangeF() {

                          for (var i:Number = 0; i < colorA.length; i++) {

                              colorA[i].val = Math.floor(Math.random() * 256);

                              colorA[i].colorChange = 2 * Math.round(Math.random()) - 1;

                          }

                      }

                      static function colorF(n:Number):Number {

                          if (!n) {

                              n = 0;

                          }

                          if (n % 2000 == 1) {

                              colorChangeF();

                          }

                          for (var i:Number = 0; i < colorA.length; i++) {

                              colorA[i].val += primeA[i] * colorA[i].colorChange;

                              if (colorA[i].val > 255) {

                                  colorA[i].val = 254;

                                  colorA[i].colorChange *= -1;

                              } else if (colorA[i].val < 0) {

                                  colorA[i].val = 1;

                                  colorA[i].colorChange *= -1;

                              }

                          }

                          return colorA[0].val << 16 | colorA[1].val << 8 | colorA[2].val;

                      }

                  }