xxxxxxxxxx
var posX = 0;
var posY = 0;
var velX = 0.5;
var velY = 0.5;
var dirX = 1;
var dirY = 1;
var rad = 20;
var dvd; //image
var colors = ["#3449eb", "#34eb3a", "#ff0000", "#ff00ea", "#00fbff", "#ffffff"]; //array of colors
var cl; //current color
function setup() {
// create canvas
createCanvas(600, 600);
//load dvd image
dvd = loadImage("DVDlogo.png");
//assign color
// Disable Strokes
noStroke();
// Set Velocities
velX = random(2, 5);
velY = random(2, 5);
posX = width / 2;
posY = height / 2;
}
function draw() {
background(100);
// Limit the movement
// if the circle leaves the canvas from left reverse the
// direction variable to -1 to move it backwards
if (posX < 0) {
// hits to left
dirX = dirX * -1;
velX = random(2, 5);
posX = 0;
colorChange();
}
else if (posX + dvd.width > width) {
// hits right, adjust posX to make sure the image stays within bounds
dirX = dirX * -1;
velX = random(2, 5);
posX = width - dvd.width; // Position the left side of the image at the right boundary
colorChange();
}
else if (posY < 0) {
//hit top
dirY = dirY * -1;
velY = random(2, 5);
posY = 0;
colorChange();
}
else if (posY + dvd.height > height) {
// hits bottom, adjust posY to make sure the image stays within bounds
dirY = dirY * -1;
velY = random(2, 5);
posY = height - dvd.height; // Position the top side of the image at the bottom boundary
colorChange();
}
posX = posX + (velX * dirX);
posY = posY + (velY * dirY);
xpos = posX;
ypos = posY;
push();
translate(xpos, ypos)
imageMode(CORNER);
image(dvd, 0, 0,);
pop();
}
function colorChange() {
cl = color(random(colors));
tint(cl);
}