unit Gard;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,   Dialogs;

type
  TForm1 = class(TForm)
   procedure FormPaint(Sender: TObject);
   procedure FormResize(Sender: TObject);
  private
   { Private declarations }
  public
   { Public declarations }
  procedure GradientRect (FromRGB, ToRGB: TColor; Canvas: TCanvas);

var
  Form1: TForm1;

implementation

{$R *.dfm}
procedure TForm1.GradientRect (FromRGB, ToRGB: TColor; Canvas: TCanvas);
var
 RGBFrom : array[0..2] of Byte; RGBDiff : array[0..2] of integer; ColorBand : TRect; I : Integer; R : Byte;
  G : Byte; B : Byte;
begin
  RGBFrom[0] := GetRValue (ColorToRGB (FromRGB));
  RGBFrom[1] := GetGValue (ColorToRGB (FromRGB));
  RGBFrom[2] := GetBValue (ColorToRGB (FromRGB));
  RGBDiff[0] := GetRValue (ColorToRGB (ToRGB)) - RGBFrom[0];
  RGBDiff[1] := GetGValue (ColorToRGB (ToRGB)) - RGBFrom[1];
  RGBDiff[2] := GetBValue (ColorToRGB (ToRGB)) - RGBFrom[2];
  Canvas.Pen.Style := psSolid;
  Canvas.Pen.Mode := pmCopy;
  ColorBand.Left := 0;
  ColorBand.Right:= canvas.ClipRect.Right-Canvas.ClipRect.Left;
  for I := 0 to $ff do
  begin
   ColorBand.Top := MulDiv (I , canvas.ClipRect.Bottom-Canvas.ClipRect.Top, $100);
   ColorBand.Bottom := MulDiv (I + 1,canvas.ClipRect.Bottom-Canvas.ClipRect.Top, $100);
   R := RGBFrom[0] + MulDiv (I, RGBDiff[0], $ff);
   G := RGBFrom[1] + MulDiv (I, RGBDiff[1], $ff);
   B := RGBFrom[2] + MulDiv (I, RGBDiff[2], $ff);
   Canvas.Brush.Color := RGB (R, G, B);
   Canvas.FillRect (ColorBand);
  end;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  GradientRect (clBlue, clBlack, Canvas);
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  Paint;
end;

end.

Копирайт © 2007, Lanselot. Все права защищены.

Используются технологии uCoz