Final Project

sketch
/*
Lauren Kenny
lkenny@andrew.cmu.edu
Section A

This program draws a grid of masks and covid particles.

*/

// ARRAY OF IMAGE LINKS
var objectLinks = [
    "https://i.imgur.com/1GlKrHl.png",
    "https://i.imgur.com/EJx0rn7.png",
    "https://i.imgur.com/uz2coXH.png",
    "https://i.imgur.com/rxFAYmh.png",
    "https://i.imgur.com/SWkTR5H.png",
    ]

// ARRAY TO STORE LOADED IMAGES
var objectImages = [];

// ARRAYS TO STORE RELEVANT IMAGE VALUES
var objectX = [0, 0, 0, 0, 0];
var objectY = [0, 0, 0, 0, 0];
var objectW = [672/8, 772/5, 847/5, 841/5, 744/8];
var objectH = [656/8, 394/5, 323/5, 410/5, 828/8];

// LOADS IMAGES
function preload() {
    for (var i=0; i<objectLinks.length; i++) {
        objectImages.push(loadImage(objectLinks[i]));
    }
}

function setup() {
    createCanvas(800, 500);
    frameRate(4);
}

function draw() {
    background(180);
    var x=0;
    var y=0;
    // CREATES A GRID OF MASK/COVID IMAGES
    for (let rows=0; rows<=height; rows+=100) {
        x=0;
        for (let cols=0; cols<=width; cols+=150) {
            i = int(random(0, objectImages.length));
            image(objectImages[i], x, y, objectW[i], objectH[i]);
            x+=150;
        }
        y+=100;
    }

    // WHEN THE MOUSE IS PRESSED, TEXT APPEARS
    if (mouseIsPressed) {
        fill(0, 0, 0, 200);
        rect(0, 0, width, height);
        fill(255);
        textSize(35);
        text('beware of covid', width/3, height/2);
        }   
}


Leave a Reply