Autor Beitrag
Matte
Hält's aus hier
Beiträge: 2



BeitragVerfasst: So 04.05.03 16:48 
Tag,

ich brauch dringend Hilfe beim Programmieren eines " Pythagoras-Baum"
Da ich dieses Projekt schon bald meinem Professor abgeben muss bin ich auf jede Hilfe wahnsinnig dankbar. Evtl. Unit + Form !

Matte


Zuletzt bearbeitet von Matte am So 04.05.03 19:56, insgesamt 1-mal bearbeitet
Phantom1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 390



BeitragVerfasst: So 04.05.03 17:05 
kein problem, ich habe zufällig mal einen programmiert, es wird nur ein timage auf der form benötigt:

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Buttons, math;

const
  TIEFE     = 10;
  VIERECK   = 100; {Pixelbreite}
  IMGWIDTH  = 800;
  IMGHEIGHT = 600;

type
  TForm1 = class(TForm)
    Image1: TImage;
    procedure FormCreate(Sender: TObject);
  private
    procedure PaintTree_Dreieck(X1,Y1,X2,Y2: Integer; c, Alpha: Double; Tiefe1: Byte);
    procedure PaintTree_Viereck(X1,Y1,X2,Y2: Integer; c, Alpha: Double; Tiefe1: Byte);
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Form1.ClientWidth:=IMGWIDTH;
  Form1.ClientHeight:=IMGHEIGHT;
  Image1.Top:=0; Image1.Left:=0;
  Image1.Width:=IMGWIDTH;
  Image1.Height:=IMGHEIGHT;
  PaintTree_Viereck(IMGWIDTH div 2 - VIERECK div 2,IMGHEIGHT - VIERECK,
                    IMGWIDTH div 2 + VIERECK div 2,IMGHEIGHT - VIERECK, VIERECK, 0,TIEFE);
end;

procedure TForm1.PaintTree_Dreieck(X1,Y1,X2,Y2: Integer; c, Alpha: Double; Tiefe1: Byte);
var
  YHilfsPoint, XHilfsPoint: Integer;
  b: Double;
begin
  b:=c/1.8;
  Alpha := Alpha + arcsin(b * sin(90/180*PI) / c) * (180/PI);
  c:=sqrt(c*c - b*b);
  XHilfsPoint := Round(X1+(c * sin((90 - Alpha)/180*PI) / sin(90/180*PI)));
  YHilfsPoint := Round(Y1-(c * sin(Alpha/180*PI) / sin(90/180*PI)));
  Image1.Canvas.Polygon([Point(X1,Y1),Point(X2,Y2),Point(XHilfsPoint,YHilfsPoint)]);
  PaintTree_Viereck(X1,Y1,XHilfsPoint,YHilfsPoint, c, Alpha, Pred(Tiefe1));
  PaintTree_Viereck(XHilfsPoint,YHilfsPoint,X2,Y2, b, Alpha-90, Pred(Tiefe1));
end;

procedure TForm1.PaintTree_Viereck(X1,Y1,X2,Y2: Integer; c, Alpha: Double; Tiefe1: Byte);
var
  XHPoint1, YHPoint1: Integer;
  YHilfsPoint, XHilfsPoint: Integer;
begin
  XHPoint1 := X1;
  YHPoint1 := Y1;
  X1 := Round(X1-(c * sin(alpha/180*PI) / sin(90/180*PI)));
  Y1 := Round(Y1-(c * sin((90 - alpha)/180*PI) / sin(90/180*PI)));
  XHilfsPoint := Round(X1+(c * sin((90 - alpha)/180*PI) / sin(90/180*PI)));
  YHilfsPoint := Round(Y1-(c * sin(alpha/180*PI) / sin(90/180*PI)));
  Image1.Canvas.Polygon([Point(XHPoint1,YHPoint1),Point(X1,Y1),
                         Point(XHilfsPoint,YHilfsPoint),Point(X2,Y2)]);
  If Tiefe1>0 Then PaintTree_Dreieck(X1,Y1,XHilfsPoint,YHilfsPoint, c, Alpha, Tiefe1);
end;

end.