Question

I am still working on a actionscript 3 color game. You have an object with a randomly generated color on the right. On the left you have another object and 3 buckets with the RGB colors. The objective is to remix the color of the right object with the 3 buckets and the left object. You carry one of the buckets over the left object. The longer the bucket is over the left object, the more of this offset is added to the object. As you now know, I am working with the red, green, and blueOffset. I now need the buckets to transform the object with CMY and not RGB. I roughly know how to convert RGB value to CMYK, but this doesn't help me when I need to use the RGB offsets to change the color of my object. I know that Actionscript 3 only has the RGB offsets and I dont know how I should solve this problem otherwise.

So my question is: Can you change the color of an movieclip in CMYK or without the ColorTransform? An idea would be very awesome.

English isn't my primary language, so sorry for mistakes...

Was it helpful?

Solution 2

I just found another real solution. If you give the coloroffset a negative value, the color gets transformed into cyan, magenta or yellow! I didn't think that it would be that easy, but it actually is. Now i just need to change my calculation so that it fits to negative stuff. But if you now mix all the buckets, the object gets black! Thats what I wanted and now im happy. The answer with the RGB to CMYK convertion is still very usefull! Thanks a lot.

OTHER TIPS

I don't think you can change the color-offset of an object to CMYK, although you can write a function to convert between RGB and CMYK. On a side note, CMYK is mainly used in printing and it might be better to just stick with RGB. That being said here is how to convert between the two.


RGB to CMYK


The range of each value in RGB is 0 to 255 and the range of each value in CMYK is 0 to 1. So we need to scale the RGB values so they fall in the 0 to 1 range.

R' = R / 255
G' = G / 255
B' = B / 255

K in CMYK represents the amount of black color and is calculated using R', G' and B'

K = 1 - max(R', G', B')

The other colors are calculated below

C = (1 - R' - K) / (1 - K)
M = (1 - G' - K) / (1 - K)
Y = (1 - B' - K) / (1 - K)

Example class:

import flash.display.MovieClip;

public class ConvertColors extends MovieClip {
    public var K:Number = 0.0;
    public var C:Number = 0.0;
    public var M:Number = 0.0;
    public var Y:Number = 0.0;

    public function convertToCMYK(R:int, G:int, B:int):void {
        var Rprime:Number = R/255;
        var Gprime:Number = G/255;
        var Bprime:Number = B/255;

        this.K = 1 - Math.max( Rprime, Math.max( Gprime, Bprime));

        this.C = (1 - Rprime - K)/(1 - K);
        this.M = (1 - Gprime - K)/(1 - K);
        this.Y = (1 - Bprime - K)/(1 - K);
    }

}

CMYK to RGB


RGB ranges from 0 to 255

R = 255 * (1 - C) * (1 - K)
G = 255 * (1 - M) * (1 - K)
B = 255 * (1 - Y) * (1 - K)

Example class:

import flash.display.MovieClip;

public class ConvertColors extends MovieClip {
    public var R:int = 0;
    public var G:int = 0;
    public var B:int = 0;

    public function convertToRGB(K:Number, C:Number, M:Number, Y:Number):void {
        var Rnum:Number = 0.0;
        var Gnum:Number = 0.0;
        var Bnum:Number = 0.0;

        Rnum = 255 * (1 - C) * (1 - K);
        Gnum = 255 * (1 - M) * (1 - K);
        Bnum = 255 * (1 - Y) * (1 - K);

        this.R = Math.round(Rnum);
        this.G = Math.round(Gnum);
        this.B = Math.round(Bnum);
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top