unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Buttons, ComCtrls;
type
TForm4 =
class(TForm)
Bild: TImage;
Label2: TLabel;
edit1: TEdit;
edit2: TEdit;
Button2: TButton;
Max: TScrollBar;
Min: TScrollBar;
Label3: TLabel;
Label1: TLabel;
Label4: TLabel;
Button1: TButton;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure MinChange(Sender: TObject);
procedure MaxChange(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
FUNCTION g(x:real):real;
var
Form4: TForm4;
ym,xm,xmax,ymax,xb,yb,k,xb2 :word;
x,y,u :real;
implementation
uses Unit2, Unit3, Unit1;
{$R *.dfm}
procedure koordinatensystem;
var intervall_1,intervall_2,i,pos,neg,n:integer;
a,b,c,d: TPoint;
begin
intervall_2 := strtoint(Form4.edit2.Text);
intervall_1 := strtoint(Form4.edit1.text);
if intervall_2<5
then k:=60;
if (intervall_2>4)
AND (intervall_2<10)
then k:=40;
if (intervall_2>9)
AND (intervall_2<15)
then k:=20;
if intervall_2>14
then k:=15;
xm := Form4.Bild.width
DIV 2;
//Hälfte der x-Achse
ym := Form4.Bild.height
DIV 2;
//Hälfte der y-Achse
xmax:= Form4.Bild.width;
ymax:= Form4.Bild.height;
form4.bild.Canvas.textout(xmax-10,ym-20,'
x');
//"x" an der x-Achse
form4.bild.canvas.textout(xm-10,1,'
y');
//"y" an der y-Achse
with Form4.Bild.canvas
do begin
font.
name:='
Arial';
font.Size:=8;
{ c
|
|
|
|
|
a———————————————————————— b
|
|
|
|
|
d }
a.x := 1; a.y := ym;
b.x := xmax; b.y := ym;
c.x := xm; c.y := 1;
d.x := xm; d.y := ymax;
//Zeichnen durch Verbinden der Punkte
moveto(a.x, a.y); lineto(b.x, b.y);
moveto(c.x, c.y); lineto(d.x, d.y);
xb:=xm-intervall_2*k;
//Beginn für die Beschriftung der x-Achse
//Achsenbeschriftung der x-Achse
FOR i:=intervall_1
TO intervall_2
DO
BEGIN
moveto(xb,ym); lineto(xb,ym+3);
Textout(xb-1,ym+10,IntToStr(i));
xb:=xb+k;
END;
{of for}
yb:=ym+intervall_2*k;
//Beginn für die Beschriftung der y-Achse
pos:=intervall_2+5;
neg:=intervall_1+5;
i:= intervall_1;
//Achsenbeschriftung der y-Achse
if {1}(intervall_2>14)
AND (intervall_2<21)
then
begin
//Verrutschen der Achsenbeschriftung
FOR n:=neg
TO pos
DO
BEGIN
moveto(xm,yb); lineto(xm+3,yb);
IF i<> 0
THEN Textout(xm+10,yb-intervall_2+10,IntToStr(i));
yb:=yb-k;
i:= i+1;
END;
{of for}
//Verrutschen der Achsenbeschriftung bei Intervall kleiner [-5;5]
if {2}intervall_2<5
then
begin
FOR n:=neg
TO pos
DO
BEGIN
moveto(xm,yb); lineto(xm+3,yb);
IF i<> 0
THEN Textout(xm+10,yb-intervall_2-20,IntToStr(i));
yb:=yb-k;
i:=i+1;
END;
{of for}
end {of if2}
end {of if1}
else
begin
//Verrutschen der Achsenbeschriftung
FOR n:=neg
TO pos
DO
BEGIN
moveto(xm,yb); lineto(xm+3,yb);
IF i<> 0
THEN Textout(xm+10,yb-intervall_2,IntToStr(i));
yb:=yb-k;
i:=i+1;
END;
{of for}
end;
{of else}
end;
{of with}
end;
procedure TForm4.BitBtn1Click(Sender: TObject);
begin
form2.PageControl1.ActivePageIndex:=1;
form2.show;
end;
procedure TForm4.Button2Click(Sender: TObject);
begin
Form4.Bild.Canvas.Brush.Color:=clWhite;
Form4.Bild.Canvas.Rectangle(0,0,form4.Bild.Width,form4.Bild.Height);
koordinatensystem;
Form4.Hide;
end;
FUNCTION g(x:real):real;
BEGIN
g:=a*x*x*x*x*x+b*x*x*x*x+c*x*x*x+d*x*x+e*x+f;
END;
procedure TForm4.FormCreate(Sender: TObject);
//Anzeigen Koordinatensystem
begin
Form4.Button1.Enabled:=true;
Form4.Bild.Canvas.Brush.Color:=clWhite;
Form4.Bild.Canvas.Rectangle(0,0,form4.Bild.Width,form4.Bild.Height);
koordinatensystem;
//Erstellen des Koordinatensystems
xm := Form4.Bild.width
DIV 2;
ym := Form4.Bild.height
DIV 2;
xmax:= Form4.Bild.width;
ymax:= Form4.Bild.height;
Form4.Bild.Canvas.font.
name:='
Arial';
Form4.Bild.Canvas.font.Size:=8;
Form4.Bild.Canvas.textout(xmax-10,ym-20,'
x');
//"x" an der x-Achse
Form4.Bild.Canvas.textout(xm-10,1,'
y');
//"y" an der y-Achse
end;
procedure Achsen;
//Löschen der Anzeige
var intervall_1,intervall_2:integer;
begin
if form4.button1.enabled=false
then
begin
Form4.Bild.Canvas.Brush.Color:=clWhite;
Form4.Bild.Canvas.Rectangle(0,0,form4.Bild.Width,form4.Bild.Height);
koordinatensystem;
//Erstellen des Koordinatensystems
intervall_2 := strtoint(form4.edit2.Text);
intervall_1 := strtoint(form4.edit1.text);
x:=intervall_1;
REPEAT //Zeichnen der Funktion
y:=g(x);
xb:=round(xm+x*k);
yb:=round(ym-y*k);
form4.Bild.Canvas.Pixels[xb,yb]:=clBlue;
x:=x+0.001;
UNTIL x > intervall_2;
end {of if}
else
begin
Form4.Bild.Canvas.Brush.Color:=clWhite;
Form4.Bild.Canvas.Rectangle(0,0,form4.Bild.Width,form4.Bild.Height);
koordinatensystem;
//Anzeigen des Koordinatensystems
end;
{of else}
end;
procedure TForm4.MinChange(Sender: TObject);
//Intervall
var x,x2:integer;
begin
//Sicherstellen, dass sich beide Regler parallel bewegen
x := Min.Position;
edit1.text := floattostr(x);
x2:= -x;
edit2.Text := FloatToStr(x2);
Max.position:= x2;
Achsen;
end;
procedure TForm4.MaxChange(Sender: TObject);
//Intervall
var x:integer;
begin
//Sicherstellen, dass sich beide Regler parallel bewegen
x := Max.Position;
edit1.text := floattostr(-x);
edit2.Text := FloatToStr(x);
Min.position:= -x;
end;
procedure TForm4.Button1Click(Sender: TObject);
//Graph anzeigen
var intervall_1,intervall_2:integer;
begin
button1.enabled:=false;
//Button "Graph anzeigen"
intervall_1 := strtoint(form4.edit1.text);
//z.B. -10
intervall_2 := strtoint(form4.edit2.Text);
//z.B. 10
//Graph löschen
Bild.Canvas.Brush.Color:=clWhite;
Bild.Canvas.Rectangle(0,0,Bild.Width,bild.Height);
Koordinatensystem;
//Parameter einlesen
a:=StrToFloat(Form3.Edit1.Text);
b:=StrToFloat(Form3.Edit2.Text);
c:=StrToFloat(Form3.Edit3.Text);
d:=StrToFloat(Form3.Edit4.Text);
e:=StrToFloat(Form3.Edit5.Text);
f:=StrToFloat(Form3.Edit6.Text);
koordinatensystem;
x:=intervall_1;
//Graph zeichnen
REPEAT
y:=g(x);
xb:=round(xm+x*k);
yb:=round(ym-y*k);
Bild.Canvas.Pixels[xb,yb]:=clBlue;
x:=x+0.001;
UNTIL x > intervall_2;
end;
end.