Delphi 经典游戏程序设计40例 的学习 例30 残留的轨迹是圆形运动
作者:互联网
unit R30; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls; type TRei30 = class(TForm) Panel1: TPanel; Button1: TButton; ScrollBar1: TScrollBar; ScrollBar2: TScrollBar; ScrollBar3: TScrollBar; Edit1: TEdit; Edit2: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; Image1: TImage; Timer1: TTimer; Edit3: TEdit; ScrollBar4: TScrollBar; Edit4: TEdit; Label4: TLabel; procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure ScrollBar1Change(Sender: TObject); procedure ScrollBar2Change(Sender: TObject); procedure ScrollBar3Change(Sender: TObject); procedure Button1Click(Sender: TObject); procedure ScrollBar4Change(Sender: TObject); private { Private declarations } public { Public declarations } end; var Rei30: TRei30; St : Byte; //按钮控制,设置状态控制指示用变量 XR,YR : Word; X,Y,DX,DY,DD,CY: Integer; //X,Y 坐标用变量,DX,DY 坐标增量(变化量)用变量, TR,QTR,DR : Extended; //DR 弧度的变化量, Col : TColor; RectD : TRect; implementation {$R *.dfm} procedure TRei30.FormCreate(Sender: TObject); begin //设置初始值, DD := 10; XR := 60; YR := 60; CY := 1; Col := clYellow; ScrollBar1.Position := DD; ScrollBar2.Position := XR; ScrollBar3.Position := YR; ScrollBar4.Position := CY; end; procedure TRei30.Timer1Timer(Sender: TObject); begin case St of 0: begin RectD := Rect(0,0,Image1.Width,Image1.Height); Image1.Canvas.Brush.Color := clBlack; Image1.Canvas.FillRect(RectD); //刷黑 Edit1.Text := ' ' + IntToStr(DD) + '°'; //显示参数 Edit2.Text := ' ' + IntToStr(XR); Edit3.Text := ' ' + IntToStr(YR); Edit4.Text := ' ' + IntToStr(CY); X := Image1.Width div 2; Y := 0; TR := - Pi / 2; DR := DD * Pi / 180; St := 1; end; 1: begin QTR := TR; TR := TR + DR; DX := Round(XR * (Cos(TR) - Cos(QTR))); //核心计算 DY := Round(YR * (Sin(TR) - Sin(QTR))); X := X + DX; Y := Y + DY + CY; Image1.Canvas.Pixels[X,Y] := clRed; //4点显示 Image1.Canvas.Pixels[X + 1,Y] := clYellow; Image1.Canvas.Pixels[X,Y + 1] := clBlue; Image1.Canvas.Pixels[X + 1,Y + 1] := clGreen; if (Y > Image1.Height + YR * 2) or (Y < -YR * 2) then begin St := 2; Edit1.Text := '绘图完成'; end; end; end; end; procedure TRei30.ScrollBar1Change(Sender: TObject); begin DD := ScrollBar1.Position; Edit1.Text := ' ' + IntToStr(DD) + '°'; DR := Pi * DD / 180; //应该去掉这行,否则在绘图中会即时的改变 end; //似乎又不行,在状态1中,W,DY值都被在计算 // 所以这里只有同步重新计算DR值 procedure TRei30.ScrollBar2Change(Sender: TObject); begin XR := ScrollBar2.Position; Edit2.Text := ' ' + IntToStr(XR); end; procedure TRei30.ScrollBar3Change(Sender: TObject); begin YR := ScrollBar3.Position; Edit3.Text := ' ' + IntToStr(YR); end; procedure TRei30.ScrollBar4Change(Sender: TObject); begin CY := ScrollBar4.Position; Edit4.Text := ' ' + IntToStr(CY); end; procedure TRei30.Button1Click(Sender: TObject); begin St := 0; end; end.
1,程序结构同前例
2,是对三角函数的应用,套用公式,不明白。
标签:begin,end,Sender,Delphi,30,TObject,40,Image1,procedure 来源: https://www.cnblogs.com/D7mir/p/16698137.html