Assignment-08-A: Mixies

sketch
//Brandon Yi
//btyi@andrew.cmu.edu
//Section A

// loading all links
var bodyLinks = [
    "http://i.imgur.com/5YM2aPE.jpg",
    "http://i.imgur.com/oKtGXfd.jpg",
    "http://i.imgur.com/Kvg75bG.jpg",
    "http://i.imgur.com/0FGzErn.jpg",
    "http://i.imgur.com/MJmlPt5.jpg",
    "http://i.imgur.com/VvX0k8e.jpg",
    "http://i.imgur.com/rLIOBoG.jpg",
    "http://i.imgur.com/q03Gko3.jpg",
    "http://i.imgur.com/BWpN5SP.jpg",
    "http://i.imgur.com/ft10TV3.jpg",
    "http://i.imgur.com/CGCZliN.jpg",
    "http://i.imgur.com/qrlc4dK.jpg"]
    
var feetLinks = [
    "http://i.imgur.com/oNSO0T6.jpg",
    "http://i.imgur.com/OWGETX7.jpg",
    "http://i.imgur.com/Zp29aVg.jpg",
    "http://i.imgur.com/AXLWZRR.jpg",
    "http://i.imgur.com/wgZq717.jpg",
    "http://i.imgur.com/sGVMEMw.jpg",
    "http://i.imgur.com/hfbrynH.jpg",
    "http://i.imgur.com/OOASUMM.jpg",
    "http://i.imgur.com/aqtIXi0.jpg",
    "http://i.imgur.com/Eu6ruPo.jpg",
    "http://i.imgur.com/mTSipwg.jpg",
    "http://i.imgur.com/1GzC4Zz.jpg"]
    
var headLinks = [
    "http://i.imgur.com/gBCZVuM.jpg",
    "http://i.imgur.com/YLOXAdH.jpg",
    "http://i.imgur.com/my3TqY7.jpg",
    "http://i.imgur.com/lvtIB9s.jpg",
    "http://i.imgur.com/gvDBfhO.jpg",
    "http://i.imgur.com/JEuJ2ER.jpg",
    "http://i.imgur.com/SbBOG1V.jpg",
    "http://i.imgur.com/cuJ5Ao1.jpg",
    "http://i.imgur.com/dqHjjig.jpg",
    "http://i.imgur.com/mcFUcHf.jpg",
    "http://i.imgur.com/0XKU9Dx.jpg",
    "http://i.imgur.com/sD1ArAR.jpg"]


//initializing arrays in problem

var headImages = [];
var bodyImages = [];
var feetImages = [];

var head = [];
var body = [];
var feet = [];

//loading links into images array 
function preload() {
    for (var i = 0; i <= 11; i++) {
        img = loadImage(headLinks[i]);
        headImages.push(img);
        img = loadImage(bodyLinks[i]);
        bodyImages.push(img);
        img = loadImage(feetLinks[i]);
        feetImages.push(img);
    }
}


function GenerateRandoms() {
    //loop for different "people"

    for (var i = 0; i <= 2; i++) {

        //generate random head image 
        r = int(random(0,11));
        head.push(headImages[r]);

        //check for repeats
        while (head[i] == head[i-1] || head[i] == head[i-2]) {
            head.pop();
            head.push(headImages[int(random(0,11))]);
        }

        //generate random body image
        r = int(random(0,11));
        body.push(bodyImages[r]);

        //check for repeats
        while (body[i] == body[i-1] || body[i] == body[i-2]) {
            body.pop();
            body.push(bodyImages[int(random(0,11))]);
        }

        //generate random feet image
        r = int(random(0,11));
        feet.push(feetImages[r]);

        //check for repeats
        while (feet[i] == feet[i-1] || feet[i] == feet[i-2]) {
            feet.pop();
            feet.push(feetImages[int(random(0,11))]);
        } 
    }

}

//setup canvas
function setup() {
    createCanvas(600, 450);
    background(220);
    GenerateRandoms();
}

function mousePressed() {

    //clearing different arrays based on different mouseY positions
    //generating new images for particular position
    if (mouseY<(height/3)) {
        head = [];
        GenerateRandoms();
    }
    else if (mouseY>=(height/3) & mouseY <=(2*height/3)) {
        body = [];
        GenerateRandoms();
    }
    else {
        feet = [];
        GenerateRandoms();
    }

    
}


//display new images in positions based on i
function draw() {
    for (var i = 0; i <= 2; i++) {
        image(head[i],i*200,0,200,150);
        image(body[i],i*200,150,200,150);
        image(feet[i],i*200,300,200,150);
    }
}

Leave a Reply