-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2
More file actions
102 lines (75 loc) · 2.5 KB
/
Copy path2
File metadata and controls
102 lines (75 loc) · 2.5 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
long double mapValue(long double value, long double fromMin, long double fromMax, long double toMin, long double toMax) {
return (value - fromMin) / (fromMax - fromMin) * (toMax - toMin) + toMin;
}
#include "../../Engine/engine.h"
#include <GL/freeglut.h>
#include <math.h>
#include <iostream>
long double angle = 0;
// Maximum number of iterations for each point on the complex plane
int maxiterations = 100;
void update();
int main(int argc, char** argv)
{
RenderEngine::setStart([]()
{
RenderEngine::background(Color(255));
RenderEngine::strokeWeight(10);
RenderEngine::stroke(0);
});
RenderEngine::setUpdate(update);
RenderEngine::Enabled(true);
}
void update()
{
long double ca = cos(angle * 3.213); //sin(angle);
long double cb = sin(angle);
angle += 0.02;
RenderEngine::background(Color::white);
int width = 800; // Assuming a window width of 800 pixels
int height = 800; // Assuming a window height of 800 pixels
long double w = 5;
long double h = (w * height) / width;
long double xmin = -w / 2;
long double ymin = -h / 2;
long double xmax = xmin + w;
long double ymax = ymin + h;
long double dx = (xmax - xmin) / width;
long double dy = (ymax - ymin) / height;
long double y = ymin;
for (int j = 0; j < height; j++) {
long double x = xmin;
for (int i = 0; i < width; i++) {
long double a = x;
long double b = y;
int n = 0;
while (n < maxiterations) {
long double aa = a * a;
long double bb = b * b;
if (aa + bb > 4.0) {
break;
}
long double twoab = 2.0 * a * b;
a = aa - bb + ca;
b = twoab + cb;
n++;
}
Color color;
if (n == maxiterations) {
color = Color(0, 0, 0); // Black
} else {
int red = static_cast<int>((n % 256));
int green = static_cast<int>((n * 5 % 256));
int blue = static_cast<int>((n * 15 % 256));
color = Color(red, green, blue);
std::cout<<color.r << color.g << color.b;
}
RenderEngine::stroke(color);
RenderEngine::point(Vector3(mapValue(i, 0, 800, -1, 1)
, mapValue(j, 0, 800, -1, 1)));
// RenderEngine::point(Vector3((long double)i / 800, (long double)j / 800, 0));
x += dx;
}
y += dy;
}
}