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。

最新文章

  1. mysql 基础
  2. 【POJ 3693】Maximum repetition substring 重复次数最多的连续重复子串
  3. Oracle - 数据库的实例、表空间、用户、表之间关系
  4. IIS不定期Crash和Oracle“未处理的内部错误(-2)”的问题分析
  5. R语言的向量化编程思维
  6. SCAU 10690 分面包
  7. Java大数操作类
  8. cat-mvc 一个nodejs mvc 框架
  9. [转] Mysql 数据库引擎
  10. ClassLoader的类结构分析
  11. assign retain copy
  12. linux文件系统目录解析
  13. 一步一步设置Joomla!开发环境
  14. Debian 8下手工安装 Eclipse CDT neon.2
  15. lua 中随机数产生
  16. RocketMQ事务消息回查设计方案
  17. Python基础教程(第3版) 笔记(一)
  18. Process对象的其他属性:
  19. Android 网络编程之---HttpClient 与 HttpURLConnection 共用cookie
  20. maven invalid loc header

热门文章

  1. ubuntu误删home目录
  2. BestCoder Round #81 (div.2)
  3. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 A、Saving Tang Monk II 【状态搜索】
  4. JVM 监控以及内存分析
  5. Code First 一
  6. JavaScript函数的方法
  7. Xcode 新建js文件
  8. 于是他错误的点名开始了(trie树)
  9. ABAP术语-Event
  10. SpringBoot配置全局自定义异常