-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
57 lines (49 loc) · 1.31 KB
/
sketch.js
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
var minval = -2.5;
var maxval = 2.5;
var minSlider;
var maxSlider;
function setup()
{
createCanvas(720,720);
pixelDensity(1);
minSlider = createSlider(minval, maxval, minval, 0.01);
maxSlider = createSlider(minval, maxval, maxval, 0.01);
}
function draw(){
var maxiterations = 100;
loadPixels();
for(var x = 0; x < width; x++)
{
for(var y = 0; y < height; y++)
{
var a = map(x, 0, width, minSlider.value(), maxSlider.value());
var b = map(y, 0, height, minSlider.value(), maxSlider.value());
var ca = a;
var cb = b;
var n = 0;
while (n < maxiterations)
{
var aa = a*a - b*b;
var bb = 2 * a * b;
a = aa + ca;
b = bb + cb;
if (abs(a + b) > 16)
{
break;
}
n++;
}
var bright = map(n, 0, maxiterations, 0, 255);
if (n == maxiterations)
{
bright = 0;
}
var pix = (x + y * width) * 4;
pixels[pix + 0] = bright;
pixels[pix + 1] = bright;
pixels[pix + 2] = bright;
pixels[pix + 3] = 255;
}
}
updatePixels();
}