永发信息网

用delphi怎么画这个函数图像,知道的说下,谢了!(100分)

答案:2  悬赏:10  手机版
解决时间 2021-08-01 05:31
  • 提问者网友:树红树绿
  • 2021-08-01 02:38

比如我想画一个二次函数的图像,y=x*x-9x+8,要怎么写代码,

就是在一个form上画这个图像,好像要用到canvas这个词,

请帮我写个画y=x*x-9x+8的代码,,,

谢谢啦!

最佳答案
  • 五星知识达人网友:梦中风几里
  • 2021-08-01 03:39
procedure TForm1.Button1Click(Sender: TObject);
var
i,x,y:integer;
a:array[1..200] of TPoint;
begin

x:=ClientWidth div 2;
y:=ClientHeight div 2;
canvas.Pen.Color := clBlue;
MoveWindowOrg( canvas.Handle, x, y );
canvas.MoveTo(-ClientWidth div 2, 0);
canvas.LineTo(ClientWidth div 2, 0);
canvas.MoveTo(0, ClientHeight div 2);
canvas.LineTo(0, -Clientheight div 2);
x:=-100;
canvas.Pen.Color := clRed;
for i:=1 to 200 do
begin
a[i].X := 5*x;
a[i].Y := -(x*x-9*x+8);
inc(x);
end;
canvas.Polyline(a);
end;


全部回答
  • 1楼网友:有你哪都是故乡
  • 2021-08-01 04:32

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.

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯