#1 29. Mai 2007 Graph Calculator (Linux) Hi Wie ich schon geschrieben habe - ich hab auch son Graph Ding gebastelt, und nun möchte ich euch das mal vorstellen und evtl. Verbesserungsvorschläge empfangen.. Hab das Ding eigtl. nur gebaut um zu gucken, ob ich's kann... also hat keinen besonderen Grund oder so. Wie ich grad sehe ist das ganze Ding 6.8 MB groß... ich weiß jedoch nicht warum. Wenn mir jemand sagen kann/will, was ich daran noch optimieren kann (am Quellcode) - danke. Spoiler Source: Code: unit Unit1; { Copyright by Telefonzelle, 2007 } {$mode objfpc}{$H+} interface uses Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls, Buttons, StdCtrls, ComCtrls, Menus; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; ComboBox1: TComboBox; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Shape1: TShape; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Calculate(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; drawn:boolean; a,b,c,d:real; y:double; funct,x: integer; implementation { TForm1 } procedure TForm1.Button1Click(Sender: TObject); begin // Ursprung: // 180 | 130 Shape1.Canvas.MoveTo(180,10); Shape1.Canvas.LineTo(180,235); Shape1.Canvas.MoveTo(10,130); Shape1.Canvas.LineTo(350,130); drawn:=true; Button1.Enabled:=false; Button2.Enabled:=true; end; procedure TForm1.Button2Click(Sender: TObject); begin try funct := ComboBox1.ItemIndex; a:= StrToFloat(Edit1.Text); b:= StrToFloat(Edit2.Text); if(funct > 1) then begin c:= StrToFloat(Edit4.Text); d:= StrToFloat(Edit3.Text); end; if(funct < 0) then begin Showmessage('You have to choose a valid function!'); end else begin Calculate(Form1); end; except Showmessage('Invalid data. A, B, C and D are only allowed to be floats. If you dont need some of those variables, just leave them empty.'); end; end; function calcY(i:integer):double; begin if(funct = 0) then begin y := 130 - (i*a) - b; end; if(funct = 1) then begin // x² + ax + b y := 130 - ((i*i) + (i*a) + (b)); end; if(funct = 2) then begin // ax^3 + bx^2 + cx + d y := 130 - ((a * (i*i*i)) + (b* (i*i)) + (c*i) + d); end; result:=y; end; procedure TForm1.Calculate(Sender: TObject); var y2,i:integer; begin Shape1.Canvas.MoveTo(180,Trunc(calcY(0))); x := 180; y := 130; Button1.Enabled:=false; Button2.Enabled:=false; Button3.Enabled:=false; i:=0; // Negative i (x) Zahlen, weil ich das irgendwie nicht beides in eine Schleife bringen konnte.. :D while(y > 0) and (x < 340) and (x > 0) and ( y < 256) do begin Application.ProcessMessages; y := calcY(i); y2 := strtoint(floattostr(y)); Shape1.Canvas.LineTo(x,y2); sleep(20); Label1.Caption := 'X: '+inttostr(i)+' Y: '+floattostr(y2); x:=x-10; i:=i-1; end; i:=0; Shape1.Canvas.MoveTo(180,Trunc(calcY(0))); x := 180; y := 130; // Positive Schleife... while(y > 0) and (x < 340) and (x > 0) and ( y < 256) do begin Application.ProcessMessages; y := calcY(i); y2 := strtoint(floattostr(y)); Shape1.Canvas.LineTo(x,y2); sleep(20); Label1.Caption := 'X: '+inttostr(i)+' Y: '+floattostr(y2); x:=x+10; i:=i+1; end; Button3.Enabled:=true; end; procedure TForm1.Button3Click(Sender: TObject); begin Shape1.Canvas.Clear; drawn:=false; Button1.Enabled:=true; Shape1.Canvas.MoveTo(0,0); Shape1.Canvas.LineTo(0,255); Shape1.Canvas.LineTo(367,255); Shape1.Canvas.LineTo(367,0); Shape1.Canvas.LineTo(0,0); end; initialization {$I unit1.lrs} end. Ist vllt. n bisschen suboptimal geschrieben, aber ich hab mit Delphi auch nicht soo viel am Hut, außer das wir das in der Schule zur Zeit "n bisschen" machen .. Hier ist die Linux Version, die für Windoof folgt wenn mir das jmd kompiliert hat, also heut Abend spätestens. http://rapidshare.com/files/34034301/graph-calculator.html MfG. Screenshot: {bild-down: http://img3.myimg.de/BildschirmfotoGraphCalcul99b.png} + Multi-Zitat Zitieren