Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Color transform help

Engaged ,
Jul 04, 2013 Jul 04, 2013

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.

TOPICS
ActionScript
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 05, 2013 Jul 05, 2013

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

...
Translate
Community Expert ,
Jul 04, 2013 Jul 04, 2013

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];

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 04, 2013 Jul 04, 2013

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);

//...

};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 04, 2013 Jul 04, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 05, 2013 Jul 05, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 05, 2013 Jul 05, 2013
LATEST

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.val = Math.floor(Math.random() * 256);

            colorA.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.val += primeA * colorA.colorChange;

            if (colorA.val > 255) {

                colorA.val = 254;

                colorA.colorChange *= -1;

            } else if (colorA.val < 0) {

                colorA.val = 1;

                colorA.colorChange *= -1;

            }

        }

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

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines