简体   繁体   English

如何在ActionScript 3中将对象的颜色偏移更改为CMYK?

[英]How can i change the color-offset of an object to CMYK in Actionscript 3?

I am still working on a actionscript 3 color game. 我仍在研究动作脚本3色游戏。 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. 在左侧,您还有另一个对象和3个RGB颜色的存储桶。 The objective is to remix the color of the right object with the 3 buckets and the left object. 目的是将右侧对象与3个存储桶和左侧对象的颜色重新混合。 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. 如您现在所知,我正在处理red,green和blueOffset。 I now need the buckets to transform the object with CMY and not RGB. 现在,我需要使用存储桶来使用CMY而不是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. 我大致知道如何将RGB值转换为CMYK,但是当我需要使用RGB偏移量更改对象的颜色时,这对我没有帮助。 I know that Actionscript 3 only has the RGB offsets and I dont know how I should solve this problem otherwise. 我知道Actionscript 3仅具有RGB偏移量,不知道如何解决该问题。

So my question is: Can you change the color of an movieclip in CMYK or without the ColorTransform? 所以我的问题是:您是否可以在CMYK中或没有ColorTransform的情况下更改动画片段的颜色? An idea would be very awesome. 一个主意会很棒。

English isn't my primary language, so sorry for mistakes... 英语不是我的主要语言,所以很抱歉出现错误...

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. 我不认为您可以将对象的色偏更改为CMYK,尽管您可以编写一个在RGB和CMYK之间转换的函数。 On a side note, CMYK is mainly used in printing and it might be better to just stick with RGB. 附带说明一下,CMYK主要用于打印,最好坚持使用RGB。 That being said here is how to convert between the two. 话虽这么说是如何在两者之间转换。


RGB to CMYK RGB到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. RGB中每个值的范围是0到255, CMYK中每个值的范围是0到1。因此,我们需要缩放RGB值,使其落在0到1范围内。

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' CMYK中的 K代表黑色量,并使用R'G'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 CMYK转RGB


RGB ranges from 0 to 255 RGB范围从0到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);
    }

}

I just found another real solution. 我刚刚找到了另一个真正的解决方案。 If you give the coloroffset a negative value, the color gets transformed into cyan, magenta or yellow! 如果将coloroffset设置为负值,则颜色将变为青色,品红色或黄色! 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! 从RGB到CMYK转换的答案仍然非常有用! Thanks a lot. 非常感谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过单击动作脚本中精灵的另一个对象来更改一种形状的颜色 - how can I change the color of one shape by clicking on clicking another object of sprite in actionscript 如何使用数组中的颜色随机更改对象的颜色? 动作3.0 - How to randomly change color of an object using colors in an array? Actionscript 3.0 如何在ActionScript 3.0中在运行时更改Label的颜色? - How can you change a Label's color at runtime in ActionScript 3.0? 如何在ActionScript 3中更改舞台的大小和颜色? - How do I change the size and color of the stage in actionscript 3? 如何计算动作3中给定十六进制颜色的阴影? - How can I calculate shades of a given hex color in actionscript 3? 使用ActionScript 3更改像素颜色 - Change pixel color with ActionScript 3 如何判断Actionscript对象是否具有某个动态属性? - How can I tell if an Actionscript object has a certain dynamic property on it? 如何获取要在Actionscript 3中与之碰撞的对象? - How can I get the object I am colliding with in Actionscript 3? 如何通过ActionScript 3在mainTimeline中更改几个MovieClip实例属性 - How can i change a couple of MovieClip instance properties in mainTimeline by ActionScript 3 如何在actionscript3中更改对象属性的值? - How to change the value of an object property in actionscript3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM