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

Delphi時鐘效果,帶指針動畫

編輯:Delphi

Delphi實現嵌入式的時鐘效果,電子鐘,帶指針走動動畫,運行程序後始獲取Windows當前時間,挺基礎的代碼:

vIEw source print? 01 unit Unit1; 02 interface 03 uses 04   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, 05   Forms, Dialogs, ExtCtrls; 06 type 07   TForm1 = class(TForm) 08     Panel1: TPanel; 09     Image1: TImage; 10     Timer1: TTimer; 11     procedure FormCreate(Sender: TObject); 12     procedure Timer1Timer(Sender: TObject); 13   private 14     { Private declarations } 15     FirstTime     : Boolean; 16     vho, vmo, vso : Real; 17   public 18     { Public declarations } 19   end; 20 var 21   Form1: TForm1; 22 implementation 23 {$R *.DFM} 24 procedure TForm1.FormCreate(Sender: TObject); 25 var 26   i : Integer; 27 begin 28   with Form1.Image1.Canvas do begin 29     Pen.Color := clWhite; 30     Pen.Style := psSolid; 31     Brush.Color := clWhite; 32     Brush.Style := bsSolid; 33     Rectangle(0,0,Width,Height); 34     Pen.Color := clBlack; 35     for i:=1 to 12 do 36       Pixels[17+Round(17*Sin(i/12.0*2*Pi)),17-Round(17*Cos(i/12.0*2*Pi))] := clBlack; 37   end; 38   FirstTime := True; 39   Form1.Panel1.Left := 0; 40   Form1.Panel1.Top := 0; 41   Form1.Width := Form1.Panel1.Width; 42   Form1.Height := Form1.Panel1.Height; 43 end; 44 procedure TForm1.Timer1Timer(Sender: TObject); 45 var 46   MyNow      : TDateTime; 47   Hour, Min, 48   Sec, mSec  : Word; 49   vh, vm, vs : Real; 50 begin 51   MyNow := Now; 52   DecodeTime(MyNow,Hour,Min,Sec,mSec); 53   vh := Hour/12.0*2*Pi; 54   vm := Min/60.0*2*Pi; 55   vs := Sec/60.0*2*Pi; 56   with Form1.Image1.Canvas do begin 57     if not FirstTime then begin 58       Pen.Color := clWhite; 59       MoveTo(17,17); 60       LineTo(17+Round(12*Sin(vho)),17-Round(12*Cos(vho))); 61       MoveTo(17,17); 62       LineTo(17+Round(15*Sin(vmo)),17-Round(15*Cos(vmo))); 63       MoveTo(17,17); 64       LineTo(17+Round(15*Sin(vso)),17-Round(15*Cos(vso))); 65     end 66     else 67       FirstTime := False; 68     Pen.Color := clBlack; 69     MoveTo(17,17); 70     LineTo(17+Round(12*Sin(vh)),17-Round(12*Cos(vh))); 71     Pen.Color := clBlack; 72     MoveTo(17,17); 73     LineTo(17+Round(15*Sin(vm)),17-Round(15*Cos(vm))); 74     Pen.Color := clRed; 75     MoveTo(17,17); 76     LineTo(17+Round(15*Sin(vs)),17-Round(15*Cos(vs))); 77   end; 78   vho := vh; 79   vmo := vm; 80   vso := vs; 81 end; 82 end.
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved