-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJulia_Set.pde
More file actions
74 lines (53 loc) · 1.52 KB
/
Copy pathJulia_Set.pde
File metadata and controls
74 lines (53 loc) · 1.52 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
void setup(){
print("Drag around your mouse on to change the constant imaginary variable of the Julia Set :)");
size(640, 480);
colorMode(HSB, 1);
}
void draw(){
float ca = map(mouseX, 0, width, -1, 1);
float cb = map(mouseY, 0, height, -1, 1);
background(255);
float w = 5;
float h = (w * height) / width;
float xmin = -w/2;
float ymin = -h/2;
float xmax = xmin + w;
float ymax = ymin + h;
float dx = (xmax - xmin) / (width);
float dy = (ymax - ymin) / (height);
loadPixels();
//int maxiterations = int(map(mouseX, 0, width, 0, 200));
int maxiterations = 100;
float y = ymin;
for (int j = 0; j < height; j++){
float x = xmin;
for (int i = 0; i < width; i++){
float a = x;
float b = y;
int iteration = 0;
while (iteration < maxiterations){
float aa = a * a;
float bb = b * b;
if (aa + bb > 4.0){
break;
}
float twoab = 2.0 * a * b;
a = aa - bb + ca;
b = twoab + cb;
iteration++;
}
if (iteration == maxiterations){
pixels[i+j*width] = color(0);
} else{
float hue = sqrt((float(iteration) / float(maxiterations)));
pixels[i+j*width] = color(hue, 255, 255);
}
x += dx;
}
y += dy;
}
print("FPS: ");
print(frameRate);
print("\n");
updatePixels();
}