这是之前写过的一个,你可以参考一下//画 y= h* sin(t)的正弦曲线unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Timer1: TTimer; procedure Button1Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { Private declarations } public y, t, h : real ; end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); var i : integer ; begin With Form1.Canvas do begin //画坐标横轴 PenPos := Point(10,240); LineTo(600,240); PenPos := Point(594,238); LineTo(600,240); PenPos := Point(594,242); LineTo(600,240); //画坐标纵轴 PenPos := Point(10,400); LineTo(10,80); PenPos := Point(8,86); LineTo(10,80); PenPos := Point(12,86); LineTo(10,80); //将Pen移至坐标原点 PenPos := Point(10,240); end; //初始化 h := 80; t := 0; Form1.Canvas.Pen.Mode := pmXOR ; Form1.Canvas.Pen.Color := clRed ; //开始画 for i := 1 to 598 do begin y := h * sin((t+i)/180*3.14159); Form1.Canvas.LineTo(Round(10+i),Round(240+y)); end; Timer1.Enabled := True ; end;procedure TForm1.Timer1Timer(Sender: TObject); var i: integer ; begin //擦除原线 y := h * sin((t+i)/180*3.14159); Form1.Canvas.PenPos := Point(10,Round(240+y)); for i := 1 to 598 do begin y := h * sin((t+i)/180*3.14159); Form1.Canvas.LineTo(Round(10+i),Round(240+y)); end; //画相移后的线 t := t + 1; y := h * sin((t+i)/180*3.14159); Form1.Canvas.PenPos := Point(10,Round(240+y)); for i := 1 to 598 do begin y := h * sin((t+i)/180*3.14159); Form1.Canvas.LineTo(Round(10+i),Round(240+y)); end; end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
y, t, h : real ;
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
i : integer ;
begin
With Form1.Canvas do begin
//画坐标横轴
PenPos := Point(10,240);
LineTo(600,240);
PenPos := Point(594,238);
LineTo(600,240);
PenPos := Point(594,242);
LineTo(600,240);
//画坐标纵轴
PenPos := Point(10,400);
LineTo(10,80);
PenPos := Point(8,86);
LineTo(10,80);
PenPos := Point(12,86);
LineTo(10,80);
//将Pen移至坐标原点
PenPos := Point(10,240);
end; //初始化
h := 80;
t := 0;
Form1.Canvas.Pen.Mode := pmXOR ;
Form1.Canvas.Pen.Color := clRed ; //开始画
for i := 1 to 598 do begin
y := h * sin((t+i)/180*3.14159);
Form1.Canvas.LineTo(Round(10+i),Round(240+y));
end;
Timer1.Enabled := True ;
end;procedure TForm1.Timer1Timer(Sender: TObject);
var i: integer ;
begin
//擦除原线
y := h * sin((t+i)/180*3.14159);
Form1.Canvas.PenPos := Point(10,Round(240+y));
for i := 1 to 598 do begin
y := h * sin((t+i)/180*3.14159);
Form1.Canvas.LineTo(Round(10+i),Round(240+y));
end; //画相移后的线
t := t + 1;
y := h * sin((t+i)/180*3.14159);
Form1.Canvas.PenPos := Point(10,Round(240+y));
for i := 1 to 598 do begin
y := h * sin((t+i)/180*3.14159);
Form1.Canvas.LineTo(Round(10+i),Round(240+y));
end;
end;end.