Ellan Suder Project 10: Interactive Sonic Sketch

When you click the program, it generates a random cat and plays the corresponding sound. At first I tried putting all the sound links in an array and using sound = loadImage(catSounds[randomCat]); like I did with the cat images, but it didn’t load fast enough and I ended up needing to load every sound at the beginning manually.

happy halloween!

var catLinks;
var catSounds;
var catInd;

function preload() {
    angrySound = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/es_angrymeow.wav");
    regularSound = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/es_meow.wav");
    scaredSound = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/es_hiss.wav");
    happySound = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/es_purr.wav");
    
    angrySound.setVolume(1);
    regularSound.setVolume(1);
    scaredSound.setVolume(1);
    happySound.setVolume(1);

    catSounds = [
    angrySound,
    regularSound,
    scaredSound,
    happySound];

    catLinks = [
    "https://i.imgur.com/NxERNed.png", //angry
    "https://i.imgur.com/OX62vqE.png", //regular
    "https://i.imgur.com/uba4Kxv.png", //scared
    "https://i.imgur.com/pZwffK9.png"]; //happy
    
    //chooses random array number
    randomCat = floor(random(catLinks.length));
    //loads random cat image from array
    cat = loadImage(catLinks[randomCat]);
}


function setup() {
    createCanvas(300, 300);
}

function draw() {
    background(255, 90, 0);
    image(cat,0,0);
}

function mousePressed() {
    //catInd records last randomCat array number
    catInd=randomCat;
    //If array number is same, pick new one. 
    //Don't show same cat in a row.
    while(randomCat==catInd)
    {
      randomCat = floor(random(catLinks.length));
    }

    cat = loadImage(catLinks[randomCat]);
    catSounds[randomCat].play();
}

Leave a Reply