xxxxxxxxxx
105
let half_w = 200, half_h = 200, zoom = 150;
let time = 0;
function setup() {
createCanvas(2*half_w, 2*half_h);
background("darkred");
stroke("white");
strokeWeight(1/zoom);
}
function disk1() {
let angle = random(TWO_PI);
let r = random() + random();
if(r > 1) r = 2 - r;
let x = r*cos(angle);
let y = r*sin(angle);
point(x, y);
}
function disk2() {
let x = 1, y = 1;
while(x*x + y*y > 1) {
x = random() * 2 - 1;
y = random() * 2 - 1;
}
point(x, y);
}
function disk3() {
let a = random();
let b = (12345*a) % 0.5;
let c = (34567*a & 2) - 1;
let d = (76543*a & 2) - 1;
let x = c * sqrt(a) * (5 / (1 + b*b) - 4);
let y = d * sqrt(a - x*x);
point(x, y);
}
function disk4() {
let r = random() + random();
if(r > 1) r = 2 - r;
let n = 10;
let t = 0;
let u = random() * sqrt(10/(n*n - 6));
while(n-- > 0) {
t = (u + t) / (1 - u*t);
}
let x = r * (1 - t*t) / (1 + t*t);
let y = r * (2*t) / (1 + t*t);
point(x, y);
}
function disk5() {
let k = random();
let r = k + (1000*k) % 1;
if(r > 1) r = 2 - r;
let x = r * cos(2*PI*k);
let y = r * sin(2*PI*k);
point(x, y);
}
function disk6() {
let x = random();
let y = random();
if(x > y) {
[x, y] = [y, x];
}
let ang = x/y * 2*PI;
let r = y;
x = r * cos(ang);
y = r * sin(ang);
point(x, y);
}
function disk7() {
// The randoms
let a = random();
let b = random();
let t = random() / 2;
// Radius
let r = a + b;
if(r > 1) r = 2 - r;
// Start in a random quadrant
let x = (a + b) > 1 ? -r : r;
let y = (a - b) < 0 ? -r : r;
// cos, sin approx
x *= 5 / (1 + t*t) - 4;
t -= 0.5;
y *= 5 / (1 + t*t) - 4;
point(x, y);
}
function draw() {
applyMatrix(zoom, 0, 0, -zoom, half_w, half_h);
disk7();
if(frameCount > 50000) noLoop();
}