14. december 2004 - 23:12
Der er
5 kommentarer og
1 løsning
'Gradient' i Delphi
Hej...
Skal bruge en Gradient funktion som denne:
procedure TForm1.FormPaint(Sender: TObject);
var
Row, Ht: Word ;
begin
Ht := (ClientHeight + 255) div 256 ;
for Row := 0 to 255 do
with Canvas do begin
Brush.Color := RGB(Row, 0{Row}, {Row}0) ;
FillRect(Rect(0, Row * Ht, ClientWidth, (Row + 1) * Ht)) ;
end ;
end;
MEN, men denne kan man kun gå fra sort til hvid eller fra sort til rød...
jeg skal bruge en funktion til at kunne gå fra RGB(A,B,C) til RGB(D,E,F)
Har selv prøvet en masse ting.. men intet har rigtig virket
14. december 2004 - 23:31
#3
ok, denne her?
procedure TForm1.Update(Sender: TObject);
Var
Xo, Yo, Max, RC, GC, BC, R, H, W : Integer;
Angle, Radius, XStep, YStep, RStep, GStep, BStep : Real;
Red, Green, Blue, Red1, Green1, Blue1,
Red2, Green2, Blue2 : Integer;
begin
{ Get form size }
H:=Image1.Height;
W:=Image1.Width;
{ Set pen width }
Image1.Canvas.Pen.Width:=1;
{ Set Max count }
Case ComboBox1.ItemIndex Of
0:Max:=H;
1:Max:=W;
2:Begin
Max:=Round(Sqrt((W+1)*(W+1)+(H+1)*(H+1)))+110;
Image1.Canvas.Pen.Width:=2;
{ Set diagonal step size }
If H>W Then
Begin
XStep:=1.0;
YStep:=2*H/Max;
End Else
Begin
YStep:=1.0;
XStep:=2*W/Max;
End;
End;
3:Begin
Max:=360*4;
Image1.Canvas.Pen.Width:=2;
{ Set circle coodinates }
Xo:=W Div 2;
Yo:=H Div 2;
Radius:=Round(Sqrt(Xo*Xo+Yo*Yo));
End;
End;
{ The GetRValue macro retrieves an intensity value for
the Red component of a 32-bit red, green, blue (RGB) value. }
Red1:=GetRValue(Shape1.Brush.Color);
{ The GetRValue macro retrieves an intensity value for
the Green component of a 32-bit red, green, blue (RGB) value. }
Green1:=GetGValue(Shape1.Brush.Color);
{ The GetRValue macro retrieves an intensity value for
the Blue component of a 32-bit red, green, blue (RGB) value. }
Blue1:=GetBValue(Shape1.Brush.Color);
Red2:=GetRValue(Shape2.Brush.Color);
Green2:=GetGValue(Shape2.Brush.Color);
Blue2:=GetBValue(Shape2.Brush.Color);
RStep:=(Red1-Red2)/Max;
GStep:=(Green1-Green2)/Max;
BStep:=(Blue1-Blue2)/Max;
{ Select starting color }
{ Call ColorToRGB to obtain an RGB representation
of a color for using with Windows API calls. }
If ColorToRGB(Shape1.Brush.Color)>ColorToRGB(Shape2.Brush.Color) Then
Begin
Red:=Red1;
Green:=Green1;
Blue:=Blue1;
End Else
Begin
Red:=Red2;
Green:=Green2;
Blue:=Blue2;
End;
{ Set starting color }
RC:=Red;
GC:=Green;
BC:=Blue;
Angle:=0;
For R:=0 To Max Do
Begin
{ set fill color }
{ The RGB macro selects a red, green, blue (RGB) color
based on the arguments supplied and the color capabilities
of the output device.
The intensity for each argument is in the range 0 through 255.
If all three intensities are zero, the result is black.
If all three intensities are 255, the result is white.}
Image1.Canvas.Pen.Color:=RGB(RC,GC,BC);
{ Fill area by drawing lines }
Case ComboBox1.ItemIndex Of
0:Begin
Image1.Canvas.MoveTo(0,R);
Image1.Canvas.LineTo(W,R);
End;
1:Begin
Image1.Canvas.MoveTo(R,0);
Image1.Canvas.LineTo(R,H);
End;
2:Begin
Image1.Canvas.MoveTo(0,Round(R*YStep));
Image1.Canvas.LineTo(Round(R*XStep),0);
End;
3:Begin
Image1.Canvas.MoveTo(Xo,Yo); Image1.Canvas.LineTo(Xo+Round(Radius*Sin(Angle*(Pi/180))),
Yo-Round(Radius*Cos(Angle*(Pi/180))));
End;
End;
{ Change fill color for each color }
RC:=Round(Red+R*RStep);
GC:=Round(Green+R*GStep);
BC:=Round(Blue+R*BStep);
{ Increase angle }
Angle:=Angle+0.25;
End;
End;