Autor Beitrag
-delphin-
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 200



BeitragVerfasst: Do 16.02.06 13:59 
Servus,
mein Problem ist eigentlich recht simpel. ich habe auf der Turtle-Komponente rekursiv die Kochsche-Kurve in mehreren Stufen zeichnen lassen und würde jetzt nur gerne wissen, wie ich die Turtle verschiedenfarbig zeichnen lasse, sodass man hinterher sehen kann, welche Linie von welcher Stufe kommt.
Thx 4 help :D
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Do 16.02.06 14:03 
Sufe der Rekursion merken und in Farbe umwandeln!

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
Horst_H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1654
Erhaltene Danke: 244

WIN10,PuppyLinux
FreePascal,Lazarus
BeitragVerfasst: Do 16.02.06 14:12 
Hallo,

in der Rekursion selbst eine globale Tiefe aendern.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
{global}
var
  tiefe : integer;

rekproc Koch(???);
begin
  Farbe= f(tiefe);
  Tiefe := Tiefe+1;
  FunktionKochkurve;
  If not(Abbruchbedingung) then
    Koch(???);
  Tiefe := Tiefe-1;
end;

BEGIN
  Tiefe:= 0;
  Koch(???);
END.


Gruss Horst

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
-delphin- Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 200



BeitragVerfasst: Do 16.02.06 14:14 
Kann man das nich easy mit Canvas machen irgendwie?
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Do 16.02.06 14:29 
Mir fehlt leider der mathematische Background aber im schlimmsten Fall musst du eine Globale Variable hochzählen und diese als Grundlage für Canvas.Font.Color nehmen. Aber du brauchst evtl. nen Faktor damit die Abweichung ins Gewicht fällt.
Horst_H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1654
Erhaltene Danke: 244

WIN10,PuppyLinux
FreePascal,Lazarus
BeitragVerfasst: Do 16.02.06 14:49 
Hallo,

Du kannst Die Farben ja vorher in einem Farbe :array of Tcolor als Konstante festlegen.
Die Tiefe ist ja nicht beliebig.
Farbe[0] := clWhite;
Hier mal die 22 Farben aus der Online-Hilfe

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
clNone  Weiß in Windows 9x, Schwarz in NT.
clAqua  Hellblau
clBlack  Schwarz
clBlue  Blau
clCream  Creme
clDkGray  Dunkelgrau
clFuchsia  Lila
clGray  Grau
clGreen  Grün
clLime  Gelbgrün
clLtGray  Hellgrau
clMaroon  Kastanienbraun
clMedGray  Mittelgrau
clMoneyGreen  Minzgrün
clNavy  Marineblau
clOlive  Olivgrün
clPurple  Purpur
clRed  Rot
clSilver  Silber
clSkyBlue  Himmelblau
clTeal  Blaugrün
clWhite  Weiß
clYellow  Gelb


Gruss Horst
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Fr 17.02.06 17:38 
ich habe gerade einen code nach delphi portiert und brauche dafür turtel, hab mir das nötigste kurzerhand selbstgeschrieben:
ausblenden volle Höhe Delphi-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:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
unit UMain;

interface

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

type
  TForm1 = class(TForm)
    Image1: TImage;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;
  TTurtle = class
    Canvas: TCanvas;
    currpos: TPoint;
    currangle: double;
    procedure f_init(apos: Tpoint; aCanvas: TCanvas);
    procedure f_forward(l: double; draw: boolean = true);
    procedure f_left(angle: double);
    procedure f_right(angle: double);
  end;

var
  Form1: TForm1;
  a: integer = 75;

implementation

{$R *.dfm}

procedure TTurtle.f_init(apos: TPoint; aCanvas: TCanvas);
begin
  currpos := apos;
  currangle := 180;
  Canvas := aCanvas;
  Canvas.MoveTo(currpos.X, currpos.Y);
end;

procedure TTurtle.f_forward(l: double; draw: boolean = true);
var
  v, u, bangle: double;
begin
  bangle := degtorad(currangle);
  v := sin(bangle) * l;
  u := cos(bangle) * l;
  currpos.x := currpos.X + round(v);
  currpos.Y := currpos.Y + round(u);
  if draw then
    Canvas.LineTo(currpos.x, currpos.y) else
      Canvas.MoveTo(Currpos.X, Currpos.y);
end;

procedure TTurtle.f_left(angle: double);
begin
  if (angle < 0) or (angle > 360) then exit;
  currangle := currangle + angle;
  if angle > 360 then currangle := currangle - 360;
end;

procedure TTurtle.f_right(angle: double);
begin
  if (angle < 0) or (angle > 360) then exit;
  currangle := currangle - angle;
  if angle < 0 then currangle := currangle + 360;
end;

procedure Draw_Quad(aTurtle: TTurtle; l: double);
var
  i: integer;
begin
  for i := 1 to 4 do
  begin
    if (i = 2) or (i = 4) then
      aTurtle.f_forward(l, false) else
        aTurtle.f_forward(l);
    aTurtle.f_right(90);
  end;
end;

procedure Pythagoras_Tree(aTurtle: TTurtle; l: double);
var
  rvalue: double;
begin
  if l > a / 10 then
    aTurtle.Canvas.Pen.Color := RGB(150, 75, 0) else
        aTurtle.Canvas.Pen.Color := clgreen;
  Draw_Quad(aTurtle, l);
  if l > 1 then
    with aTurtle do
    begin
      f_forward(l, false);
      f_left(30);
      Pythagoras_Tree(aTurtle, l * 0.5 * sqrt(3));
      f_right(90);
      f_forward(l * 0.5 * sqrt(3), false);
      Pythagoras_Tree(aTurtle, l * 0.5);
      f_forward(-l * 0.5 * sqrt(3), false);
      f_left(60);
      f_forward(-l, false);
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  aTurtle: TTurtle;
begin
  image1.Picture.Bitmap := nil;
  aTurtle := TTurtle.Create;
  aTurtle.f_init(point(image1.width div 2 - a div 2, image1.height), image1.canvas);
  try
    Pythagoras_Tree(aTurtle, a);
  finally
    aTurtle.Free;
  end;
end;

Initialization
  randomize;

end.


der 2. parameter bei f_forward ist praktisch, wenn der neue punkt gesetzt aber nicht gezeichnet werden soll, wie es teilweise bei diesem baum der fall ist.

eine verbesserung wäre noch statt currpos: TPoint 2 doubles zu nehmen, das würde die genauigkeit eventuell erhöhen, vielleicht auch nicht, müsste man sehen.