-
Notifications
You must be signed in to change notification settings - Fork 0
/
fractal plant.pas
95 lines (82 loc) · 2.25 KB
/
fractal plant.pas
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
uses
GraphABC;
const
STEP = 3.0;
RAD = pi / 180;
type
data = record
x := 0;
y := 200;
angle := 45;
constructor Create(x: integer; y: integer; angle: integer);
begin
Self.x := x;
Self.y := y;
Self.angle := angle;
end;
end;
var
stack: System.Collections.Generic.Stack<data> := new System.Collections.Generic.Stack<data>();
str: string := 'X';
angle := 45;
x := 0;
y := 0;
procedure go();
begin
var dx := trunc(STEP*cos(angle*RAD) - STEP*sin(angle*RAD));
var dy := trunc(STEP*sin(angle*RAD) + STEP*cos(angle*RAD));
Line(x, y, x + dx, y + dy);
x += dx;
y += dy;
end;
begin
var n := 1;
readln(n);
Coordinate.OriginX := trunc(Window.Height / 2);
Coordinate.OriginY := trunc(Window.Width / 2);
Coordinate.SetMathematic();
for var i := 1 to n do
begin
var pos := 1;
while pos <= length(str) do
begin
var flag := false;
if (pos <= length(str)) and (str[pos] = 'X') then
begin
delete(str, pos, 1);
insert('F-[[X]+X]+F[+FX]-X', str, pos);
pos += 18;
flag := true;
end;
if (pos <= length(str)) and (str[pos] = 'F') then
begin
delete(str, pos, 1);
insert('FF', str, pos);
pos += 2;
flag := true;
end;
if flag = false then
pos += 1;
end;
end;
for var i := 1 to length(str) do
begin
if (str[i] = 'F') then
go();
if str[i] = '-' then
angle -= 25;
if str[i] = '+' then
angle += 25;
if str[i] = '[' then
begin
stack.Push(new data(x, y, angle));
end;
if str[i] = ']' then
begin
var res: data := stack.Pop();
x := res.x;
y := res.y;
angle := res.angle;
end;
end;
end.