Create color gradient
This tutorial create color gradient white to yellow by drawing horizontal lines. Each line has a different color value.
Bookmark:
Create color gradient
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. This example simply draws lines horizontally with different color values.
At startup create the color gradient.
procedure TForm1.FormCreate(Sender: TObject); Var C, R, H, W : Integer; Step : Real; begin { Get form size } H:=Image1.Height; W:=Image1.Width; { Set fill step size } Step:=255/H; C:=0; For R:=0 To H Do Begin { Select color for gradient starting from white to yellow } { 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(255,255,255-C); { Fill area by drawing lines } { Changes the current drawing position to the point (X,Y). Use MoveTo to set the value of PenPos before calling LineTo. Calling MoveTo is equivalent to setting the PenPos property.} Image1.Canvas.MoveTo(0,R); { Draws a line on the canvas from PenPos to the point specified by X and Y, and sets the pen position to (X, Y). } Image1.Canvas.LineTo(W,R); { Chenge fill color } C:=Round(R*Step); End; end;
Download This Delphi Tutorials.
Download materials for this article (Delphi - Tutorials)
color-gradient.zip
File size: 4 KB, File type: zip
Total downloads: 225, Upload date: February 10 - 2009
moh :: February 20-2009 :: 04:30 PM
merçi de votre services