Delphi Tutorial


 

Color gradient

 

      

Download this example

         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 example

Click here to download this complete example for Delphi 6. (File size 4KB)

 

 

Go top

 


Previous Page First Page Next Page
 
Copyright © 2002 digitalcoding.com. All rights reserved.