unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, jpeg, ExtCtrls, StdCtrls, Buttons;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit3: TEdit;
Image1: TImage;
procedure Button1Click(Sender: TObject);
procedure Image1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var a, b, c: real;
// Graph zeichnen
procedure TForm1.FormCreate(Sender: TObject);
var i: integer;
begin
with Image1.Canvas
do
begin
moveto(20, 220);
lineto(420, 220);
// x-Achse
moveto(220, 20);
lineto(220, 420);
// y-Achse
moveto(410, 215);
lineto(422, 220);
lineto(410, 225);
// x-Pfeil
moveto(215, 30);
lineto(220, 18);
lineto(225, 30);
// y-Pfeil
textout(425, 225, '
x');
// Beschriftung
for i := -3
to 3
do
begin
moveto(220 + 50 * i, 215);
lineto(220 + 50 * i, 225);
// x-Einteilung
moveto(215, 220 + 50 * i);
lineto(225, 220 + 50 * i);
// y-Einteilung
textout(222 + 50 * i, 225, inttostr(i));
// Zahlen x-Achse
if i <> 0
then
textout(205, 213 + 50 * i, inttostr(-i));
// Zahlen y-Achse
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i, j: integer; x, y: real;
begin
a := strtofloat(Edit1.Text);
// Eingabe
b := strtofloat(Edit2.Text);
i := 20;
while i < 420
do
begin
i := i + 1;
x := (i - 220) / 50;
y := a * x + b;
j := round((220 - y * 50));
Image1.Canvas.Pixels[i, j] := clred;
Image1.Canvas.Pen.Color := clred;
Image1.Canvas.textout(400, 42, '
y=ax+b');
// Beschriftung
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var i, j: integer; x, y: real;
begin
a := strtofloat(Edit1.Text);
// Eingabe
b := strtofloat(Edit2.Text);
c := strtofloat(Edit3.Text);
i := 70;
while i < 420
do
begin
i := i + 1;
x := (i - 220) / 50;
// x skalieren
y := a * sqr(x) + b * x + c;
// Funktion y=ax²+bx+c
j := round((220 - y * 50));
// j berechnen
Image1.Canvas.Pixels[i, j] := clgreen;
// zeichnen
Image1.Canvas.textout(400, 100, '
y=ax²+bx+c');
// Beschriftung
end;
end;
end.