xxxxxxxxxx
74
let cricket
let ladybug
let stinkbug
let bumblebee
let buggies = []
function setup() {
createCanvas(400, 400);
//cricket = new Bug("green")
//ladybug = new Bug("red")
//stinkbug = new Bug("brown")
//bumblebee = new Bug("yellow")
for (let i=0; i<300; i++){
buggies[i] = new Bug()
}
}
function draw() {
background(220);
noStroke()
for (let i=0; i<300; i++){
buggies[i].stay()
buggies[i].move()
buggies[i].display()
}
//noStroke()
//cricket.stay()
//ladybug.stay()
//stinkbug.stay()
//bumblebee.stay()
//cricket.move()
//ladybug.move()
//stinkbug.move()
//bumblebee.move()
//cricket.display()
//ladybug.display()
//stinkbug.display()
//bumblebee.display()
}
class Bug {
constructor(tempC){
this.x = random(width)
this.y = random(height)
this.xSpeed = random(-3,3);
this.ySpeed = random(-3,3)
this.c = color(random(255), random(255), random(255))
}
display(){
fill(this.c)
circle(this.x,this.y,20)
}
move(){
this.x = this.x + this.xSpeed
this.y = this.y + this.ySpeed
}
stay(){
if (this.x > width || this.x < 0){
this.xSpeed = this.xSpeed * -1
}
if (this.y > height || this.y < 0){
this.ySpeed = this.ySpeed * -1
}
}
}