xxxxxxxxxx
53
//lesson from coding train
let bubbles = [];
let trot = [];
let horse;
function preload() {
for(let i = 0; i < 4; i++) {
trot[i] = loadImage("trot"+i+ ".png");
}
}
function setup() {
createCanvas(400, 400);
}
function mouseDragged() {
let r = random(10, 100);
let b = new Bubble(mouseX, mouseY, r);
bubbles.push(b);
}
function draw() {
background(20, 255, 20);
for (let bubble of bubbles) {
bubble.move();
bubble.show();
}
}
class Bubble {
constructor(x, y, r,img) {
this.x = x;
this.y = y;
this.r = r;
this.trot= img;
}
move() {
this.x = this.x + random(-5, 5);
this.y = this.y + random(-5, 5);
}
show() {
image(trot[0], this.x, this.y, this.r, this.r);
}
}