xxxxxxxxxx
43
let pg;
let colors = [
"#8287ac",
"#c062a4",
"#e9365b",
]
function setup() {
createCanvas(800, 800);
pg = createGraphics(width,height);
pg.noStroke();
}
function draw() {
background(220);
const circles= getRandomCircles(3000,width,height);
circles.forEach((c) =>{
pg.fill(random(colors));
pg.circle(c.x, c.y, c.z)
});
image(pg,0,0);
noLoop();
}
keyPressed = () => {
if (key === 's') {
saveCanvas(canvas, 'canvas', 'png');
//saveGif('canvas', 4);
}
};
function getRandomCircles(_num, _w, _h) {
let circles = [];
for (let i = 0; i < _num; i++) {
let x = random(-1, 1) * _w;
let y = random(-1, 1) * _h;
let z = random(120, 180);
if (circles.every((c) => dist(x, y, c.x, c.y) > (z + c.z) * 0.5)) {
circles.push(createVector(x, y, z));
}
}
return circles;
}