Delphi实例之绘制正弦函数图像
2024-10-22 05:05:26
Delphi实例之绘制正弦函数图像
unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls; type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);
var
x,l:Integer;
y,a:double;
begin
Image1.Picture.Bitmap:=TBitMap.Create;
Image1.Picture.Bitmap.Width:=Image1.Width;
Image1.Picture.Bitmap.Height:=Image1.Height;
l:=Image1.Picture.Bitmap.Width;
{下面的语句用于绘制直角坐标系}
Image1.Canvas.MoveTo(,(Image1.Height div ));
Image1.Canvas.Pen.Color:=clBlue;
Image1.Canvas.LineTo(Image1.Width,(Image1.Height div ));{绘制函数图像X轴}
Image1.Canvas.MoveTo((Image1.Width div ),Image1.Height);
Image1.Canvas.LineTo((Image1.Width div ),);{绘制函数图像Y轴}
for x:= to l do
begin
a:=(x/l)**Pi;{角度化弧度}
y:=sin(*a);{为了加强美观效果,这里讲振幅设为2}
y:=y*(Image1.Picture.Bitmap.Height/);
y:=y+(Image1.Picture.Bitmap.Height/);
Image1.Picture.Bitmap.Canvas.Brush.Style:=bsSolid;
Image1.Picture.Bitmap.Canvas.Pixels[Trunc(x),Trunc(y)]:=clRed;{当然也可以用LineTo过程来实现,但是要注意设置Pen.Width到合适的值}
end;
label1.Visible:=true;
Label2.Visible:=true;
label3.Visible:=true;
Label4.Visible:=true;
label5.Visible:=true;
Label6.Visible:=true;
end; end.
注意,这里我用了四个标签,分别用于显示X,Y,0,f(x)=sinx,并事先将它们的Visible属性设为False,当图像绘制完成后在将Visible改为True。
最新文章
- mysql 基础
- 【POJ 3693】Maximum repetition substring 重复次数最多的连续重复子串
- Oracle - 数据库的实例、表空间、用户、表之间关系
- IIS不定期Crash和Oracle“未处理的内部错误(-2)”的问题分析
- R语言的向量化编程思维
- SCAU 10690 分面包
- Java大数操作类
- cat-mvc 一个nodejs mvc 框架
- [转] Mysql 数据库引擎
- ClassLoader的类结构分析
- assign retain copy
- linux文件系统目录解析
- 一步一步设置Joomla!开发环境
- Debian 8下手工安装 Eclipse CDT neon.2
- lua 中随机数产生
- RocketMQ事务消息回查设计方案
- Python基础教程(第3版) 笔记(一)
- Process对象的其他属性:
- Android 网络编程之---HttpClient 与 HttpURLConnection 共用cookie
- maven invalid loc header