[英]Create highlight and shadow in ActionScript 3
有誰知道如何基於 ActionScript 3 中的一種顏色創建兩種新顏色(高光和陰影)? 那么,如果我有紅色 (0xFF0000),我也會得到淺紅色和深紅色嗎?
我不知道。 謝謝!
要獲得高光(亮度),請將每個 R、G 和 B 均等增加相同的量(最大值為255
或0xFF
)。 在您的情況下,紅色已經達到最大值,因此將綠色和藍色增加相同的數量(例如,在每個通道上執行+= 128
)。
為了獲得陰影(黑暗),您將每個 R、G 和 B 均等地減少相同的量(最小值為0
或0x00
)。 在您的情況下,綠色和藍色都已經處於最小值,因此只需將紅色減少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.