画正弦线:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
r, t: integer;
a1, m: real;
bmp: TBitmap;
begin
if (strtoint(edit1.Text) < 0) or (strtoint(edit1.Text) > 10000000) or
(edit1.Text = ' ') then
begin
showmessage('请输入一个1到10000000之间的数!');
exit;
end;
bmp := Tbitmap.create;
bmp.Width := Image1.Width;
bmp.Height := Image1.Height;
bmp.Canvas.Pen.Color := RGB(random(255), random(255), random(255));
;
for t := 1 to 5000 do
begin
a1 := t * 3.1415926 / 180;
m := 100 * cos(strtoint(edit1.Text) * a1);
if t = 1 then
begin
//移动Penpos到当前第一点;
bmp.Canvas.MoveTo(0, trunc(m) + 200);
end
else
begin
bmp.Canvas.lineto(t, trunc(m) + 200);
end;
end;
image1.Picture.Bitmap.Assign(bmp);
bmp.Free;
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
Button1Click(Sender);
end;
end.