我需要創建4個顏色漸變邏輯。其中一個帖子給了我計算4種顏色梯度的模式。但是我有差異來實現它。4顏色漸變邏輯需要
我能計算出E點的顏色(中間的一個),但我不知道如何開發梯度從中
我的代碼
COLORREF NewColor = RGB(255,0,0);
COLORREF NewColor2 = RGB(0,255,0);
COLORREF NewColor3 = RGB(0,0,255);
COLORREF NewColor4 = RGB(255,255,0);
red_low = GetRValue(NewColor);
blue_low = GetBValue(NewColor);
green_low = GetGValue(NewColor);
red_high = GetRValue(NewColor2);
green_high= GetGValue(NewColor2);
blue_high = GetBValue(NewColor2);
red_low2 = GetRValue(NewColor3);
blue_low2 = GetBValue(NewColor3); // divide the difference in colours by the number of steps
green_low2 = GetGValue(NewColor3);
red_high2 = GetRValue(NewColor4);
green_high2 = GetGValue(NewColor4); // divide the difference in colours by the number of steps
blue_high2 = GetBValue(NewColor4);
double distance_a = sqrt((double)((0-W)^2+(0-H/2)^2));
double distance_b = sqrt((double)((350-W/2)^2+(0-H/2)^2));
double distance_c = sqrt((double)((350-W/2)^2+(100-H/2)^2));
double distance_d = sqrt((double)((0-W/2)^2+(100-H/2)^2));
double sum_distances = distance_a + distance_b + distance_c + distance_d;
double red = (red_low*distance_a + red_high*distance_b + red_low2*distance_c+ red_high2*distance_d)/sum_distances;
double green = (green_low*distance_a + green_high*distance_b + green_low2*distance_c+ green_high2*distance_d)/sum_distances;
double blue = (blue_low*distance_a + blue_high*distance_b + blue_low2*distance_c+ blue_high2*distance_d)/sum_distances;
COLORREF Color_E= RGB(red,green,blue);
安逸幫助如何futher碼是讚賞。
你想做什麼?插入矩形的顏色? NewColori是角落裏的顏色嗎? – user168715 2010-06-04 19:45:12
是的,我想創建一個方形或四角有四種顏色的矩形。屏幕上的每個像素應顯示這四種顏色的適當組合。我需要使用SetPixel或使用memcpy複製到frambuffer。新顏色是角落處的顏色。 – user358791 2010-06-04 19:53:00
您*需要使用''中的LinearGradientBrush來做到這一點。沒有重新發明那個輪子的意義。 –
2010-06-04 20:16:40