xxxxxxxxxx
63
let x;
let y;
let wdth;
let hght;
let xspeed;
let yspeed;
let dvd;
let r,g,b;
function preload() {
dvd = loadImage("dvd_logo.png");
}
function setup() {
createCanvas(800, 600);
wdth = 120;
hght = 90;
x = random(1, width);
y = random(1, height);
xspeed = 10;
yspeed = 10;
}
function pickColor() {
r = random(10, 255);
g = random(10, 255);
b = random(10, 255);
}
function draw() {
background(0);
//rect(x, y, 80, 60);
if (x + wdth >= width) {
xspeed = -xspeed;
x = width - wdth;
pickColor();
} else if (x <= 0) {
xspeed = -xspeed;
x = 0;
pickColor();
}
if (y + hght >= height) {
yspeed = -yspeed;
y = height - hght;
pickColor();
} else if (y <= 0) {
yspeed = -yspeed;
y = 0;
pickColor();
}
tint(r, g, b);
image(dvd, x, y, wdth, hght);
x += xspeed;
y += yspeed;
}