~/Desktop/fungsi.
pas Page 1
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Image1: TImage;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
function f(x:real):real;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function tform1.f(x:real):real;
begin
f:= x*x;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
button1.Caption:='OK';
button2.Caption:='fungsi y = x';
button3.Caption:='fungsi y = −2x';
button4.Caption:='fungsi y = sin (x)';
button5.Caption:='fungsi y = sin (3x)';
button6.Caption:='fungsi y = sin (x) + x';
edit1.Text:='0';
edit2.Text:='';
end;
procedure TForm1.Button1Click(Sender: TObject);
var x,y:real;
i,x0,y0:integer;
begin
x:=strToFloat(edit1.Text);
y:=f(x);
edit2.Text:=floatToStr(y);
//gambar
x0:=image1.Width div 2;
y0:=image1.Height div 2;
image1.Canvas.Pen.Color:=clLime;
image1.Canvas.MoveTo(0,y0);
image1.Canvas.LineTo(image1.Width,y0);
image1.Canvas.Pen.Color:=clBlue;
image1.Canvas.MoveTo(x0,0);
image1.Canvas.LineTo(x0,image1.Height);
for i:=−100 to 100 do begin
x:=i/10;
y:=f(x);
image1.Canvas.Pixels[x0+i,y0−round(y)]:=clRed;
end;
~/Desktop/fungsi.pas Page 2
end;
end.