for(let i = 1; i <= 6; i++){
img = loadImage(`DVD${i}.png`);
createCanvas(windowWidth, windowHeight);
mover = new Mover(random(dvdLogos));
dir = random([PI/4, PI/4 + HALF_PI, PI/4 + PI, -PI/4].map(e => p5.Vector.fromAngle(e))).setMag(speed);
describe("Classic DVD screensaver with an upsetting twist");
bounce(walls, mover.getCorners());
image(img, x, y, r*0, r*0);
if (x > width - r || x < r) {
if (y > height - r || y < r) {
function bounce(walls, corners){
let ap = p5.Vector.sub(cnr, wall.start);
let ab = p5.Vector.sub(wall.end, wall.start);
let reflectionVector = createVector(-ab.y, ab.x);
let normal = p5.Vector.add(wall.start, ab);
let d = p5.Vector.dist(cnr, normal);
let inBoundsOfWall = p5.Vector.dist(wall.start, cnr) <= wall.getWallLength() && p5.Vector.dist(wall.end, cnr) <= wall.getWallLength();
if(d <= speed && inBoundsOfWall ){
dir.reflect(reflectionVector);
function generateWalls(){
walls.push(new Wall(wallOffset + dvdw*1.05,wallOffset,width-wallOffset -dvdw*1.05,wallOffset));
walls.push(new Wall(width-wallOffset,wallOffset + dvdh*1.05,width-wallOffset,height-wallOffset-dvdh*1.05));
walls.push(new Wall(width-wallOffset-dvdw*1.05,height-wallOffset,wallOffset + dvdw*1.05,height-wallOffset));
walls.push(new Wall(wallOffset,height-wallOffset-dvdh*1.05,wallOffset,wallOffset+dvdh*1.05));