繁体   English   中英

在 ActionScript 3 中创建高光和阴影

[英]Create highlight and shadow in ActionScript 3

有谁知道如何基于 ActionScript 3 中的一种颜色创建两种新颜色(高光和阴影)? 那么,如果我有红色 (0xFF0000),我也会得到浅红色和深红色吗?

我不知道。 谢谢!

要获得高光(亮度),请将每个 R、G 和 B 均等增加相同的量(最大值为2550xFF )。 在您的情况下,红色已经达到最大值,因此将绿色和蓝色增加相同的数量(例如,在每个通道上执行+= 128 )。

为了获得阴影(黑暗),您将每个 R、G 和 B 均等地减少相同的量(最小值为00x00 )。 在您的情况下,绿色和蓝色都已经处于最小值,因此只需将红色减少x量(例如,在红色通道上执行 a -= 128 )。

简而言之:
输入 = 0xFF0000 ... 然后高光 = 0xFF8080和阴影 = 0x800000

更新:
关于其他颜色(或色调)的高光/阴影情况的评论中提出了一个很好的观点。 如果我们同意“更亮”意味着添加更多白色而“更暗”意味着添加更多黑色那么线性插值可能会对您有所帮助(基本上使输入颜色渐变为黑色或白色并选择您喜欢的更深/更浅的颜色那些 A 到 B 的路径...

PS:通过插值,您可以灵活地混合不同的色调和明暗度。 也许从鲜红色混合到更深的红紫色(而不仅仅是黑色)以获得“更甜美”的阴影颜色,并且您的绿色可以有黄色亮点(而不仅仅是白色)。 蓝色由你决定。

用法示例:

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

示例 function:
(注意: (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