xxxxxxxxxx
70
let circles;
const colors = ["#850F8D","#B51B75","#6DC5D1","#0E46A3","#640D6B"];
function setup() {
createCanvas(800,800);
fill(0);
strokeWeight(1.2);
const num = 100000;
circles = getRandomCircles(num,800*0.4,800*0.4,100);
}
function draw() {
background(220);
translate(width/2,height/2);
const n = 120;
circles.forEach((c) => {
violet(n, c.x, c.y, c.z/2);
//noFill();
//ircle(c.x,c.y,c.z);
noLoop();
});
}
keyPressed = () => {
if (key === 's') {
saveCanvas(canvas, 'image', 'png');
//saveGif('canvas', 4);
}
};
function violet(n, xx, yy, size){
const angle =360/n;
const r =15;
push();
translate(xx,yy);
const c = random(colors);
fill(c);
stroke(c)
for(let i=0;i<n;i++){
//const sinR = abs(sin(i));
const sinR = sin(i)*cos(i/3);
const rm = map(sinR,0,1,size-5,size);
const x = rm*cos(radians(angle*i));
const y = rm*sin(radians(angle*i));
const xx = r*cos(radians(angle*i));
const yy = r*sin(radians(angle*i));
line(xx,yy,x,y);
circle(x,y,2);
}
noFill();
stroke(220);
strokeWeight(0.5);
for(let i = 0;i<10;i++){
circle(random(-5,5),random(-5,5),r*2);
}
pop();
}
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, 200); // z軸の値を円の大きさとして使用
if (circles.every((c) => dist(x, y, c.x, c.y) > (z + c.z) * 0.5)) {
circles.push(createVector(x, y, z));
}
}
return circles;
}