程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi生成圖像的動畫效果 代碼實例

Delphi生成圖像的動畫效果 代碼實例

編輯:Delphi

Delphi使用是Shape 控件、Timer 控件和BitBtn 控件等實現動畫效果,本例中主要是結合Shape 控件生成各種圖形,利用Timer 控件的OnTimer 事件控制動畫效果產生的時間。完整代碼:

vIEw source print? 001 unit Unit1; 002 interface 003 uses 004 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 005 ExtCtrls, StdCtrls, Buttons; 006 type 007 TForm1 = class(TForm) 008 Timer1: TTimer; 009 Shape1: TShape; 010 BitBtn1: TBitBtn; 011 BitBtn2: TBitBtn; 012 BitBtn3: TBitBtn; 013 procedure Timer1Timer(Sender: TObject); 014 procedure BitBtn1Click(Sender: TObject); 015 procedure BitBtn2Click(Sender: TObject); 016 procedure BitBtn3Click(Sender: TObject); 017 private 018 { Private declarations } 019 public 020 { Public declarations } 021 end; 022 var 023 Form1: TForm1; 024 Start:boolean; 025 implementation 026 {$R *.DFM} 027 procedure TForm1.Timer1Timer(Sender: TObject); 028 begin 029 if start then 030 begin 031 Randomize; 032 Form1.shape1.Brush.Color:=RGB(random(255),random(255),random(255)); 033 Randomize; 034 //隨機設置畫筆模式 035 case random(8of 036 0:Form1.Shape1.Brush.Style:=bsSolid; 037 1:Form1.Shape1.Brush.Style:=bsBdiagonal; 038 2:Form1.Shape1.Brush.Style:=bsVertical; 039 3:Form1.Shape1.Brush.Style:=bsFdiagonal; 040 4:Form1.Shape1.Brush.Style:=bsDiagCross; 041 5:Form1.Shape1.Brush.Style:=bsCross; 042 6:Form1.Shape1.Brush.Style:=bsHorizontal; 043 7:Form1.Shape1.Brush.Style:=bsClear; 044 end; 045 randomize; 046 Form1.Shape1.pen.Color:=RGB(random(255),random(255),random(255)); 047 randomize; 048 Form1.shape1.pen.Width:=random(10)+1; 049 randomize; 050 //隨機設置繪圖模式 051 case random(16of 052 0:Form1.shape1.pen.mode:=pmBlack; 053 1:Form1.shape1.pen.mode:=pmNotxor; 054 2:Form1.shape1.pen.mode:=pmXor; 055 3:Form1.shape1.pen.mode:=pmNotMask; 056 4:Form1.shape1.pen.mode:=pmNotMerge; 057 5:Form1.shape1.pen.mode:=pmMerge; 058 6:Form1.shape1.pen.mode:=pmMaskNotPen; 059 7:Form1.shape1.pen.mode:=pmMaskPenNot; 060 8:Form1.shape1.pen.mode:=pmMaskNotPen; 061 9:Form1.shape1.pen.mode:= pmMergePenNot; 062 10:Form1.shape1.pen.mode:=pmMergeNotpen; 063 11:Form1.shape1.pen.mode:=pmNotCopy; 064 12:Form1.shape1.pen.mode:=pmCopy; 065 13:Form1.shape1.pen.mode:=pmNot; 066 14:Form1.shape1.pen.mode:=pmNop; 067 15:Form1.shape1.pen.mode:=pmWhite; 068 end; 069 Randomize; 070 //隨機設置繪圖風格 071 case random(7of 072 0:Form1.shape1.Pen.Style:=psSolid; 073 1:Form1.shape1.Pen.Style:=psDash; 074 2:Form1.shape1.Pen.Style:=psDot; 075 3:Form1.shape1.Pen.Style:=psDashDot; 076 4:Form1.shape1.Pen.Style:=psDashDotDot; 077 5:Form1.shape1.Pen.Style:=psClear; 078 6:Form1.shape1.Pen.Style:=psInsideFrame; 079 end; 080 randomize; 081 //設置Shape 控件的形狀,共有6 種形狀可選 082 case random(7of 083 0:Form1.shape1.shape:=stRectangle; 084 1:Form1.shape1.shape:=stSquare; 085 2:Form1.shape1.shape:=stRoundRect; 086 3:Form1.shape1.shape:=stRoundSquare; 087 4:Form1.shape1.shape:=stEllipse; 088 5:Form1.shape1.shape:=stCircle; 089 end; 090 end; 091 end; 092 procedure TForm1.BitBtn1Click(Sender: TObject); 093 begin 094 start:=true;//圖形動畫開始 095 end; 096 procedure TForm1.BitBtn2Click(Sender: TObject); 097 begin 098 start:=False;//圖形動畫停止 099 end; 100 procedure TForm1.BitBtn3Click(Sender: TObject); 101 begin 102 Close; 103 end; 104 end.
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved