-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
112 lines (96 loc) · 2.64 KB
/
main.c
File metadata and controls
112 lines (96 loc) · 2.64 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
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
#include <stdio.h>
#include <math.h>
const unsigned int MAX_ITERATIONS = 1000;
unsigned int Iterations (double firstX, double firstY)
{
unsigned int iteration = 0;
double x = firstX;
double y = firstY;
// Escape time algorithm
while (x*x + y*y <= 4 && iteration < MAX_ITERATIONS)
{
double xNew = x*x - y*y + firstX;
double yNew = 2*x*y + firstY;
if (
(xNew == x && yNew == y) ||
(xNew == firstX && yNew == firstY)
)
{
return MAX_ITERATIONS; // Point is in the set
}
x = xNew;
y = yNew;
iteration++;
}
return iteration;
}
int main() {
const float xYZoomRatio = 2;
const double moveSpeed = 10;
const double zoomSpeed = 1.3;
const unsigned int screenWidth = 220;
const unsigned int screenHeight = 60;
double zoom = 30.0;
char charsetLength = 68;
char charset[] = "@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\\|()1{}[]?-_+~<>i!lI;:,\"^`'.";
double xCenter = 0.0;
double yCenter = 0.0;
while (1)
{
for (unsigned int y = 0; y < screenHeight; y++)
{
for (unsigned int x = 0; x < screenWidth; x++)
{
unsigned int iter = Iterations(
(y + yCenter - 45.0) / zoom,
(x + xCenter - 110.0) / (zoom * xYZoomRatio)
);
if (iter == MAX_ITERATIONS)
{
printf("%c", ' ');
}
else
{
printf("%c", charset[(int)powf((iter / (float)MAX_ITERATIONS) * charsetLength, 1.5) % charsetLength]);
}
}
puts("|");
}
char decision;
printf("Current position: (%.2f, %.2f)\n", xCenter, yCenter);
puts("MOVE: w/a/s/d, ZOOM: q/e, QUIT: x");
scanf(" %c", &decision);
switch (decision)
{
case 'w':
yCenter -= moveSpeed;
break;
case 'a':
xCenter -= moveSpeed;
break;
case 's':
yCenter += moveSpeed;
break;
case 'd':
xCenter += moveSpeed;
break;
case 'q':
zoom /= zoomSpeed;
yCenter /= zoomSpeed;
xCenter /= zoomSpeed;
break;
case 'e':
zoom *= zoomSpeed;
yCenter *= zoomSpeed;
xCenter *= zoomSpeed;
break;
case 'x':
return 0;
break;
default:
puts("Invalid input!");
break;
}
}
return 0;
}