简体   繁体   English

在 ActionScript 3 中创建高光和阴影

[英]Create highlight and shadow in ActionScript 3

Does anyone know how to create two new colours (highlight and shadow) based on one colour in ActionScript 3?有谁知道如何基于 ActionScript 3 中的一种颜色创建两种新颜色(高光和阴影)? So, if I have red (0xFF0000), I will get a light red and dark red too?那么,如果我有红色 (0xFF0000),我也会得到浅红色和深红色吗?

I have no idea.我不知道。 Thanks!谢谢!

To get Highlight (lightness) you increase each R, G and B equally by same amount (with maximum at 255 or 0xFF ).要获得高光(亮度),请将每个 R、G 和 B 均等增加相同的量(最大值为2550xFF )。 In your case Red is already at its maximum so increase both Green and Blue by same amount ( eg do a += 128 on each of those channels).在您的情况下,红色已经达到最大值,因此将绿色和蓝色增加相同的数量(例如,在每个通道上执行+= 128 )。

To get Shadow (darkness) you decrease each R, G and B equally by same amount (with minimum at 0 or 0x00 ).为了获得阴影(黑暗),您将每个 R、G 和 B 均等地减少相同的量(最小值为00x00 )。 In your case both Green and Blue are already at their minimum so just decrease only Red by x amount ( eg do a -= 128 on Red channel).在您的情况下,绿色和蓝色都已经处于最小值,因此只需将红色减少x量(例如,在红色通道上执行 a -= 128 )。

In short:简而言之:
Input = 0xFF0000 ... then Highlight = 0xFF8080 and Shadow = 0x800000 .输入 = 0xFF0000 ... 然后高光 = 0xFF8080和阴影 = 0x800000

Update:更新:
A good point was made in the comments about highlight/shadow cases of other colours (or hues).关于其他颜色(或色调)的高光/阴影情况的评论中提出了一个很好的观点。 If we agree that "lighter" means adding more white and "darker" means adding more black then maybe a linear interpolation might help you (basically make a gradient of input colour fading to black or to white and choose your preferred darker/lighter colour along those A-to-B paths...如果我们同意“更亮”意味着添加更多白色而“更暗”意味着添加更多黑色那么线性插值可能会对您有所帮助(基本上使输入颜色渐变为黑色或白色并选择您喜欢的更深/更浅的颜色那些 A 到 B 的路径...

PS: By interpolating, you'll have the flexibility of blending to different hues and shades of lightness/darkness. PS:通过插值,您可以灵活地混合不同的色调和明暗度。 Maybe blend from a bright red towards a darker reddish-purple (instead of just black) for "sweeter" shade colours, and your greens could have yellow highlights (instead of just white).也许从鲜红色混合到更深的红紫色(而不仅仅是黑色)以获得“更甜美”的阴影颜色,并且您的绿色可以有黄色亮点(而不仅仅是白色)。 Blue is up to you.蓝色由你决定。

example usage:用法示例:

var newColour :uint = 0;
newColour = blendRGB_AS3 (0xFF0000, 0xFFFFFF, 0.5) //# get 50% white added
newColour = blendRGB_AS3 (0xFF0000, 0x000000, 0.5) //# get 50% black added

Example function:示例 function:
(note: (temp_int >> 0) is used here as a quick Math.Floor for any fractioned results) (注意: (temp_int >> 0)在这里用作任何分数结果的快速Math.Floor

//# function inputs: src_C, dest_C, stopPoint ... where:
//# src_C = source / start colour A (as 0xRGB)
//# dest_C = destination / end colour B (as 0xRGB)
//# stopPoint = A-to-B stopping point (as ranging from 0.0 to 1.0)

function blendRGB_AS3 (src_C, dest_C, stopPoint ) :uint
{
    //# using Unsigned INTegers since no need of the minus ( - ) sign.
    var temp_int :uint = 0; var res_C :uint = 0;
    
    var src_R :uint = (src_C >> 16 & 0xFF);
    var src_G :uint = (src_C >> 8 & 0xFF);
    var src_B :uint = (src_C >> 0 & 0xFF);
    
    var dst_R :uint = (dest_C >> 16 & 0xFF);
    var dst_G :uint = (dest_C >> 8 & 0xFF);
    var dst_B :uint = (dest_C >> 0 & 0xFF);
    
    //# Now for each R, G, B Channel... 
    //# calculate the mid-point value then merge that into output of "res_C"
    
    //# for Red
    temp_int = src_R + stopPoint * (dst_R - src_R);
    res_C = ( (temp_int >> 0) << 16);
    
    //# for Green
    temp_int = src_G + stopPoint * (dst_G - src_G);
    res_C |= ( (temp_int >> 0)  << 8);
    
    //# for Blue
    temp_int = src_B + stopPoint * (dst_B - src_B);
    res_C |= ( (temp_int >> 0)  << 0);
    
    return res_C; //# gives: example 0xFF0000 if red
    
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM