比如我想画一个二次函数的图像,y=x*x-9x+8,要怎么写代码,
就是在一个form上画这个图像,好像要用到canvas这个词,
请帮我写个画y=x*x-9x+8的代码,,,
谢谢啦!
比如我想画一个二次函数的图像,y=x*x-9x+8,要怎么写代码,
就是在一个form上画这个图像,好像要用到canvas这个词,
请帮我写个画y=x*x-9x+8的代码,,,
谢谢啦!
unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
type TForm1 = class(TForm) procedure FormPaint(Sender: TObject); procedure FormResize(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormPaint(Sender: TObject); var x: Integer; y: Integer; begin //y=x*x-9x+8 Canvas.Pen.Width:=2; Canvas.MoveTo(0,Trunc(self.ClientHeight)); for x := 0 to self.ClientWidth do begin y := x*x-9*x+8; Canvas.LineTo(x, y); end;
end;
procedure TForm1.FormResize(Sender: TObject); begin Refresh;
end;
procedure TForm1.FormCreate(Sender: TObject); begin self.DoubleBuffered:=true;
end;
end.