xxxxxxxxxx
45
const colors = ["#FEFFDB","#FFC60B","#FF8B00","#444444"]
function setup() {
createCanvas(800, 800);
rectMode(CENTER);
noStroke();
}
function draw() {
background(220);
translate(width/2,0);
hisi_group(10);
noLoop();
}
keyPressed = () => {
if (key === 's') {
saveCanvas(canvas, 'canvas', 'png');
//saveGif('canvas', 4);
}
};
// 個数分ひし形を重ねる
const hisi_group = (n) =>{
const y = height*2/n;
for(let i = 0;i<n;i++){
fill(random(colors));
hisi(0,y*i,width/1.5);
//rect(0,y*i,width/2,height/2);
}
}
// ひし形を作る
const hisi = (x,y,r) =>{
const angle = 360/4;
beginShape();
for(let i = 0;i<4;i++){
const xx = r*cos(radians(i*angle));
const yy = r*sin(radians(i*angle));
vertex(x+xx,y+yy);
}
endShape(CLOSE);
}