有誰知道如何在 ActionScript 3 中基于一種顏色創建兩種新顏色(高光和陰影)?那么,如果我有紅色(0xFF0000),我也會得到淺紅色和深紅色嗎?
我不知道。謝謝!
uj5u.com熱心網友回復:
要獲得高光(亮度),您將每個 R、G 和 B 均等地增加相同的量(最大值為255或0xFF)。在您的情況下,紅色已經達到最大值,因此將綠色和藍色都增加相同的數量(例如 = 128,在每個通道上做一個)。
要獲得陰影(暗度),您將每個 R、G 和 B 均等地減少相同的量(最小值為0或0x00)。在您的情況下,綠色和藍色都已經處于最小值,因此只需將紅色減少x量(例如,-= 128在紅色通道上執行)。
簡而言之:
Input = 0xFF0000... 然后 Highlight =0xFF8080和 Shadow = 0x800000。
更新:
在關于其他顏色(或色調)的高光/陰影情況的評論中提出了一個很好的觀點。如果我們同意“較淺”意味著添加更多白色,而“較深”意味著添加更多黑色,那么線性插值可能會對您有所幫助(基本上使輸入顏色漸變為黑色或白色,然后選擇您喜歡的較暗/較淺的顏色)那些 A-to-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
示例函式:(
注意:(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
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/455007.html
