xxxxxxxxxx
71
//https://en.wikipedia.org/wiki/Julia_set
var R = 2;
var cx = 0.285, cy = 0.01;
/*
(0.285, 0.01)
(-0.7269, 0.1889)
(-0.8, 0.156)
(-0.4, 0.6)
(-0.74543, 0.11301)
(-0.75, 0.11)
(-0.1, 0.651)
*/
var MAX_ITER = 100;
var sliderX, sliderY;
var redrawBtn;
function setup() {
createCanvas(500, 500);
colorMode(HSB, 100);
pixelDensity(1);
sliderX = createSlider(-1.00, 1.00, cx, 0.01);
sliderY = createSlider(-1.00, 1.00, cy, 0.01);
redrawBtn = createButton("Redraw");
redrawBtn.mousePressed(draw);
}
function draw() {
loadPixels();
// noprotect
for(px = 0; px < width; px++){
for(py = 0; py < height; py++){
var x = map(px, 0, width, -R, R);
var y = map(py, 0, height, -R, R);
var n = 0;
while(x*x + y*y < R*R && n < MAX_ITER){
var xTemp = x*x - y*y;
y = 2*x*y + sliderY.value() /*cy*/;
x = xTemp + sliderX.value() /*cx*/;
n++;
}
//Colored
var h = (255 * n) / MAX_ITER;
var s = 255;
var v = (n < MAX_ITER) ? 255 : 0;
set(px, py, color(h, s, v));
//Black & White
/*var c = map(n, 0, MAX_ITER, 0, 1);
c = map(sqrt(c), 0, 1, 0, 255);
if(n === MAX_ITER)
c = 0;
var pix = (px + py * width) * 4;
pixels[pix + 0] = c;
pixels[pix + 1] = c;
pixels[pix + 2] = c;
pixels[pix + 3] = 255;*/
}
}
updatePixels();
noLoop();
}