xxxxxxxxxx
58
function setup() {
createCanvas(600, 600);
}
function draw() {
background(220);
let spacing = 20;
let gap = 50;
let num = 5;
let diam = (width-(gap*2)-(spacing*num))/num;
for (i=gap; i< (height-gap); i+= diam + spacing) {
for (j=gap; j< (width-gap); j+= diam + spacing){
ladybug(diam, j, i);
}
}
}
function ladybug(diam, x, y) {
push();
let radius = diam/2;
translate(x+radius,y+radius);
//face
fill(0);
let fx = 0;
let fy = 0;
ellipse(fx,fy, radius);
//body
let cx = 0;
let cy = radius/2;
let newd = diam*0.75
noStroke(0);
fill(255,0,0);
ellipse(cx, cy, newd);
//split
stroke(0);
fill(0);
let newr = newd/2;
beginShape(TRIANGLES);
vertex(0+cx, cy-newr);
vertex(4+cx, cy+newr);
vertex(cx-2, cy+newr);
endShape();
//dots
fill(0);
let dotdiam = 5;
let bound = newr-(dotdiam/2)-2;
ellipse(cx+noise(y)*bound, cy+ noise(x), dotdiam);
ellipse(cx+noise(x)*bound, cy - noise(y)*bound, dotdiam);
ellipse(cx-noise(x)*bound, cy + noise(y)*bound, dotdiam);
ellipse(cx-noise(x)*bound, cy - noise(y)*bound, dotdiam);
pop();
}