xxxxxxxxxx
53
let cricket
let ladybug
let stinkbug
let bumblebee
function setup() {
createCanvas(400, 400);
cricket = new Bug("green")
ladybug = new Bug("red")
stinkbug = new Bug("brown")
bumblebee = new Bug("yellow")
print("cricket x: " + cricket.x)
print("ladybug x: " + ladybug.x)
print("stinkbug x: " + stinkbug.x)
print("bumblebee x: " + stinkbug.x)
}
function draw() {
background(220);
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 = tempC
}
display(){
fill(this.c)
circle(this.x,this.y,20)
}
move(){
this.x = this.x + this.xSpeed
this.y = this.y + this.xSpeed
}
}