-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fractal1.cpp
105 lines (85 loc) · 2.43 KB
/
Fractal1.cpp
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
#include<iostream>
#include<graphics.h>
#include<math.h>
#include "./canvas.h"
using namespace std;
#define PI 3.14159265
//Fractal Class
class Fractals{
SVG S;
void Decide_color(int itr){
switch (itr){
case 1:
setcolor(YELLOW);
break;
case 2:
setcolor(LIGHTGREEN);
break;
case 3:
setcolor(GREEN);
break;
case 4:
setcolor(LIGHTRED);
break;
default:
setcolor(BROWN);
break;
}
}
void frac1(float length, float angle, int itr){
if(itr > 0){
//this means there is still some hope for new branches
//decide the branch color
Decide_color(itr);
//shrink length
length *= 0.67;
//taking right branch first
Point cursor_backup(S.getCursor(0), S.getCursor(1));
cursor_backup._0 = S.getCursor(2);
//rotate cursor right
S.rotate_cursor(-angle);
S.Line(length);
frac1(length, angle, itr-1);
//color decision for second branch
Decide_color(itr);
//restore current itr's cursor backup data
S.set_cursor(cursor_backup.x, cursor_backup.y, cursor_backup._0);
S.rotate_cursor(angle);
S.Line(length);
frac1(length, angle, itr-1);
}
return;
}
public:
void Tree(float length, float angle, int itr){
//draw the root explicitly!
setcolor(BROWN);
S.rotate_cursor(90);
S.Line(length);
//following point will work as a seed...
Point P(S.getCursor(0), S.getCursor(1));
cout<<"\nFractals initialized!";
frac1(length, angle, itr);
cout<<"\nFractals Complete!";
}
};
int main(){
int itr;
float angle, length;
cout<<"\n>Length: ";
cin>>length;
cout<<">Angle: ";
cin>>angle;
int gd=0, gm;
initgraph(&gd, &gm, NULL);
getch();
for(itr=0; itr<11; itr++){
cleardevice();
Fractals F;
F.Tree(length, angle, itr);
delay(500);
}
getch();
closegraph();
return 0;
}