-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoPainter.c
More file actions
81 lines (68 loc) · 1.57 KB
/
AutoPainter.c
File metadata and controls
81 lines (68 loc) · 1.57 KB
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
#define MinArea 0.5
#define MinEdge 0.15
void SubdivideCanvas(double x, double y, double width, double height)
{
double divider;
if (width * height >= MinArea)
{
if (width > height)
{
divider = width * RandomReal(MinEdge, 1 - MinEdge);
MovePen(x + divider, y);
DrawLine(0, height);
SubdivideCanvas(x, y, divider, height);
SubdivideCanvas(x + divider, y, width - divider, height);
}
else
{
divider = height * RandomReal(MinEdge, 1 - MinEdge);
MovePen(x, y + divider);
DrawLine(width, 0);
SubdivideCanvas(x, y, width, divider);
SubdivideCanvas(x, y + divider, width, height - divider);
}
}
}
#define pi 3.1415926535
void DrawPolarLine(double r, double theta)
{
double radians = theta / 180 * pi;
DrawLine(r * cos(radians), r * sin(radians));
}
void DrawFractalLine(double len, double theta, int order)
{
if (order == 0)
{
DrawPolarLine(len, theta);
}
else
{
DrawFractalLine(len / 3, theta, order - 1);
DrawFractalLine(len / 3, theta - 60, order - 1);
DrawFractalLine(len / 3, theta + 60, order - 1);
DrawFractalLine(len / 3, theta, order - 1);
}
}
void KochFractal(double size, int order)
{
double x0, y0;
x0 = GetWindowWidth() / 2 - size / 2;
y0 = GetWindowHeight() / 2 - sqrt(3) * size / 6;
MovePen(x0, y0);
DrawFractalLine(size, 0, order);
DrawFractalLine(size, 120, order);
DrawFractalLine(size, 240, order);
}
int main(void)
{
/*
InitGraphics();
Randomize();
SubdivideCanvas(0, 0, GetWindowWidth(), GetWindowHeight());
*/
InitGraphics();
double size = 8;
int order = 4;
KochFractal(size, order);
return 0;
}