用Delphi制作美丽的万花规
?牐燨1是大圆圆心,O2是小圆圆心,T是小圆上的一点,S是T到O2的长度,R1是大圆的半径,R2是小圆的半径,由图(^35020501a^)开始,小圆逆时针自转到图(^35020501b^)位置时两圆心连线与水平线相比已转过了a1角度,小圆的新切点与圆心和T点已转过了a2角度,因此:
?牐燼1*R1=a2*R2
?牐燼2=(R1/R2)*a1
?牐燭点的新座标为:
?牐燲b:=-(R1-R2)*cos(a1)-s*cos(a2-a1);?牔?
?牐燳b:=(R1-R2)*sin(a1)-s*sin(a2-a1);??
?牐牶昧耍碇懒耍颐蔷屠词导什僮鳌F舳疍elphi 5.0,新建一个窗体,加入一个定时器,写入如下代码:
?牐爑nit Unit1:
?牐爄nterface
?牐爑ses
?牐燱indows,Messages,SysUtils,Classes,Graphics,Controls,Forms,Dialogs,
?牐燬tdCtrls,ExtCtrls;
?牐爐ype
?牐燭Form1 = class(TForm)??
?牐燘utton1:TButton??
?牐燭imer1:TTimer;
?牐爌rocedure FormPaint(Sender: TObject);?牔?
?牐爌rocedure Timer1Timer(Sender: TObject):?牔?
?牐爌rivate
?牐爗?? Private declarations}
?牐爌ublic
?牐爗?? Public declarations}
?牐爀nd;
?牐爒ar
?牐燜orm1: TForm1;??
?牐燫1,R2,S:integer; //R1大圆半径,R2小圆半径;S为小圆上的任意一点到圆心距离
?牐燲b:array[1..1000] of integer;
?牐燳b:array[1..1000] of integer;
?牐燲t,Yt,W,H,i:integer;
?牐?//Xb,Yb定义为小圆上一点座标,W,H大圆圆心座标
?牐燼1,a2:Real;//a1定义为大圆角度,a2定义为小圆角度
?牐爄mplementation
?牐爐ype TCube = array[0..1000] of Integer;
?牐爗$R *.DFM}??
?牐爌rocedure TForm1.FormPaint(Sender:TObject);?牔?
?牐燽egin
?牐爁orm1.Refresh;?牔? //清空
?牐燫1:=240;
?牐燫2:=72;
?牐燬:=34;
?牐爓:=form1.Width div 2;
?牐爃:=form1.Height div 2;
?牐燫andomize;
?牐爁orm1.Canvas.Pen.Color??=Random(65535)
?牐燙anvas.LineTo((w-R1*2) div 2,h div 2);?牔?
?牐爊:=0;
?牐爀nd;
?牐爌rocedure TForm1.Timer1Timer(Sender:TObject);?牔?
?牐燽egin
?牐爁orm1.Refresh(); //清空
?牐燫andomize;
?牐爁orm1.Canvas.Pen.Color:=Random(65535);??
?牐?//定义随机色
?牐燫2:=Random(R1-10); //循环增量
?牐燬:=Random(R2-2);?牔?
?牐燙anvas.MoveTo(w-(R1-R2+S),h); //初始变量
?牐爁or i:=1 to 20000 do
?牐燽egin
?牐燼1:=(pi/360)*i;??
?牐燼2:=(R1/R2)*a1;??
?牐燲t:=Trunc(-(R1-R2)*cos(a1)-s*cos(a2-a1)+w);?牔?
?牐燳t:=Trunc((R1-R2)*sin(a1)-s*sin(a2-a1)+h;?牔?
?牐燙anvas.LineTo(Xt,Yt);?牔?
?牐爀nd;
?牐爄f R2+10>R1 then form1.Refresh(); //清空
?牐爀nd;
?牐爀nd.
?牐牶昧耍碏9,运行程序后的效果图如(^35020501c^),相信你还能做出更加美妙的图案来。以上程序在Windows98和Delphi 5.0下调试通过。
?牐?