Four color gradient

Four color gradient

Four color gradient

This tutorial shows how to create four color gradients.

DownloadDownload This Tutorials

Bookmark:

Four 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.

Color gradient

Following procedure create gradient at startup.

procedure TForm1.FormCreate(Sender: TObject);
Var
     C, R, H, W, L : Integer;
     Step : Real;
begin
     { Get form size }
     H:=Image1.Height;
     W:=Image1.Width;

     { Set fill size }
     L:=W Div 3;

     { Set fill step size }
     Step:=255/L;

     C:=0;
     For R:=0 To W Do
     Begin
     { Select color for gradient starting from RED to YELLOW }
          { Change fill color }
          If R<=L Then
          Begin
               C:=Round(R*Step);
               { Red -> Green }
               Image1.Canvas.Pen.Color:=RGB(255-C,C,0)
          End
          Else If R<=2*L Then
          Begin
               C:=Round((R-L)*Step);
               { Green -> Blue }
               Image1.Canvas.Pen.Color:=RGB(0,255-C,C)
          End
            Else If R<=3*L Then
          Begin
               C:=Round((R-2*L)*Step);
               { Blue -> Yellow }
               Image1.Canvas.Pen.Color:=RGB(C,C,255-C);
          End;

          { Fill area by drawing lines }
          Image1.Canvas.MoveTo(R,0);
          Image1.Canvas.LineTo(R,H);
     End;
end;

Download This Delphi Tutorials.

Download materials for this article (Delphi - Tutorials)

Download - four-color-gradient.zipfour-color-gradient.zip
       File size: 4 KB, File type: zip
       Total downloads: 119, Upload date: February 10 - 2009

Leave a comment