问大家 一下,在delphi 画函数的图象,如画出 y=sin x 的图象?(50分)

  • 主题发起人 主题发起人 a_sand
  • 开始时间 开始时间
A

a_sand

Unregistered / Unconfirmed
GUEST, unregistred user!
问大家 一下,在delphi 画函数的图象,如画出 y=sin x 的图象?
 
刚好手边有一个例子,给你贴出来看看。用canvas画的,变量 x 是基于窗体的。
---------------------
var
Form1: TForm1;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var i,j:integer; x,y:real; halfheight:integer;
begin
form1.Refresh;
halfheight:=form1.Height div 2;

for i:=1 to trunc(form1.Width) do
begin
x:=i*(4*PI/form1.Width);
y:=sin(x); //halfheight*0.7
j:=trunc(y*100)+halfheight;
canvas.Pixels[i,j]:=clred;
end;

x:=3*form1.Width/4; //画竖线
i:=trunc(x);
with canvas do
begin
pen.Color:=clgreen;
moveto(i,0);
lineto(i,form1.Height);
end;
end;

procedure TForm1.FormPaint(Sender: TObject);
var x,y:real; i,j:integer;
begin
x:=form1.Width/4; //坐标系
i:=trunc(x);
y:=form1.Height/2;
j:=trunc(y);
with canvas do
begin
moveto(i,0);
lineto(i,form1.Height);
moveto(0,j);
lineto(form1.Width,j);
end;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
Var
Degree : Integer;
begin
canvas.Pen.Color:=clblue;
canvas.MoveTo(0,200);
with canvas do
begin
for degree :=0 to 10000 do
begin
LineTo(degree, 200+round(10*sin(degree/6.28)));
end;
end;
end;
 
定义x的范围和步长,求出y,用lineto(x,y)
 
接受答案了.
 
后退
顶部