xxxxxxxxxx
let bugs = [];
function setup() {
createCanvas(600, 600);
noLoop();
strokeWeight(0);
fill(40);
colorMode(HSB);
background(54, 16, 95);
}
function makeBug(x, y, s) {
push();
translate(x, y);
//ellipse(0, 0, s, s);
//body segments x3
let bc = random(360);
fill(bc, 50, 20);
ellipse(0, -s * 0.15, random(s * 0.15, s * 0.25), random(s * 0.33, s * 0.5));
ellipse(0, 0, random(s * 0.15, s * 0.33), random(s * 0.33, s * 0.5));
ellipse(0, s * 0.15, random(s * 0.15, s * 0.33), random(s * 0.33, s * 0.5));
//antennae
stroke(bc, 50, 20);
strokeWeight(2);
noFill();
let a, b, c, d;
a = random(0, s * 0.1);
b = s * 0.15;
c = random(0, s * 0.15);
d = random(s * 0.25, s * 0.4);
line(a, -b, c, -d);
line(-a, -b, -c, -d);
//legs x6
stroke(bc, 50, 20);
strokeWeight(2);
noFill();
a = 0;
b = 0;
c = random(s * 0.1, s * 0.25);
d = random(s * 0.1, s * 0.25);
line(a, -b, c, -d);
line(-a, -b, -c, -d);
line(a, b, c, d);
line(-a, b, -c, d);
line(a, b + s / 6, c, d + s / 6);
line(-a, b + s / 6, -c, d + s / 6);
//wings
strokeWeight(0);
fill(random(360), 50, 80, 0.6);
let rot = random(0.9, 1.3);
let l = random(s * 0.5, s * 0.75);
rotate(PI * rot);
arc(0, -s * 0.15, s * 0.33, l, 3 * PI / 2, PI / 2);
rotate(-PI * rot);
rotate(-PI * rot);
arc(0, -s * 0.15, s * 0.33, l, PI / 2, 3 * PI / 2);
rotate(PI * rot);
rot = random(0.9, 1.3);
l = random(s * 0.5, s * 0.75);
rotate(PI * rot);
arc(0, -s * 0.15, s * 0.33, l, 3 * PI / 2, PI / 2);
rotate(-PI * rot);
rotate(-PI * rot);
arc(0, -s * 0.15, s * 0.33, l, PI / 2, 3 * PI / 2);
rotate(PI * rot);
fill(random(360), 50, 80);
rot = random(rot, 1.4);
//l = random(s*0.5, s*0.75);
rotate(PI * rot);
arc(0, -s * 0.15, s * 0.33, l, 3 * PI / 2, PI / 2);
rotate(-PI * rot);
rotate(-PI * rot);
arc(0, -s * 0.15, s * 0.33, l, PI / 2, 3 * PI / 2);
pop();
}
function draw() {
//s = width/13;
//for (let i=s; i<width-s/2; i+=s){
// for (let j=s; j<height-s/2; j+=s){
// makeBug(i, j, s);
// }
//}
while (bugs.length < 50) {
let bug = {
x: random(width),
y: random(height),
d: random(20, 50)
};
var overlapping = false;
for (var j = 0; j < bugs.length; j++) {
var other = bugs[j];
var d = dist(bug.x, bug.y, other.x, other.y);
if (d < bug.r + other.r) {
overlapping = true;
break;
}
}
if (!overlapping) {
bugs.push(bug);
}
for (let i = 0; i < bugs.length; i++) {
makeBug(bugs[i].x, bugs[i].y, bugs[i].r * 2)
}
}
}