程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi生成漸變色-閃爍矩形

Delphi生成漸變色-閃爍矩形

編輯:Delphi

Delphi生成漸變色效果,生成閃爍矩形代碼,一共生成有4種效果,1、菱形擴散效果,2、中心向左右擴散,3、中心向上下擴散,4、動畫矩形效果,整體的運行效果如下:

Delphi生成漸變色-閃爍矩形

vIEw source print? 01 unit Unit1; 02 interface 03 uses 04   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 05   Dialogs, StdCtrls, ExtCtrls; 06 type 07   TForm1 = class(TForm) 08     Button1: TButton; 09     Image1: TImage; 10     Image2: TImage; 11     Label1: TLabel; 12     Label2: TLabel; 13     Image3: TImage; 14     Label3: TLabel; 15     Image4: TImage; 16     Timer1: TTimer; 17     Label4: TLabel; 18     procedure Button1Click(Sender: TObject); 19     procedure Timer1Timer(Sender: TObject); 20     procedure FormDestroy(Sender: TObject); 21   private 22     { Private declarations } 23   public 24     { Public declarations } 25   end; 26 var 27   Form1: TForm1; 28 implementation 29 {$R *.dfm} 30 procedure TForm1.Button1Click(Sender: TObject); 31 var i:Integer; 32 begin 33 With Image1 Do 34 For i:=0 To 64 DO     //菱形擴散效果 35    Begin 36    Canvas.Brush.Color:=RGB(3*i+45,3*i+45,3*i+45); 37    Canvas.FillRect(Rect(i,i,64,64)); 38    Canvas.FillRect(Rect(i,128-i,64,64)); 39    Canvas.FillRect(Rect(128-i,i,64,64)); 40   Canvas.FillRect(Rect(128-i,128-i,64,64)); 41    end; 42 With Image2 Do         // 中心向左右擴散 43 For i:=0 To 64 DO 44    Begin 45    Canvas.Brush.Color:=RGB(3*i+45,3*i+45,3*i+45); 46    Canvas.FillRect(Rect(i,0,i+1,128)); 47    Canvas.FillRect(Rect(128-i,0,128-i+1,128)); 48 end; 49 With Image3 Do        //中心向上下擴散 50 For i:=0 To 64 DO 51    Begin 52    Canvas.Brush.Color:=RGB(3*i+45,3*i+45,3*i+45); 53    Canvas.FillRect(Rect(0,i,128,i+1)); 54    Canvas.FillRect(Rect(0,128-i+1,128,128-i)); 55    end; 56 Timer1.enabled:=True; 57  end; 58 procedure TForm1.Timer1Timer(Sender: TObject); 59 var k:Integer; 60 begin 61 With Image4 Do 62 For k:=0 To 64 DO     //動畫矩形效果 63    Begin 64    Canvas.Brush.Color:=RGB(Random(255),Random(255),Random(255)); 65    Canvas.FillRect(Rect(k,k,64,64)); 66    Canvas.FillRect(Rect(k,128-k,64,64)); 67    Canvas.FillRect(Rect(128-k,k,64,64)); 68   Canvas.FillRect(Rect(128-k,128-k,64,64)); 69    end; 70 end; 71 procedure TForm1.FormDestroy(Sender: TObject); 72 begin 73 Timer1.Enabled:=False;  //關閉時鐘 74 end; 75 end.
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved