Project 10 – Sound Story

sketchDownload
// Storyline: 4 fruits (an orange, a banana, a red apple, and a green apple)
    // are inside a fruitbowl together and the fruit keep disappearing!!
    // I'm still having trouble with setting up a local server
    // Right now these sounds are attached to the web server chrome method
    // But it doesn't seem to be working and I don't know why
var x; //x position of the fruits
var y; //y position of the fruits
var dx = 4 //starting speed the fruits fly away at for x
var dy = 4 //starting speed the fruits fly away at for y
var orangeScream;
var bananaScream;
var redAppleScream;
var greenAppleScream;

function preload() {
    orangeScream = loadSound ("http://127.0.0.1:8887/orangeScream.wav");
    bananaScream = loadSound ("http://127.0.0.1:8887/bananaScream.wav");
    redAppleScream = loadSound ("http://127.0.0.1:8887/redAppleScream.wav");
    greenAppleScream = loadSound ("http://127.0.0.1:8887/greenAppleScream.wav");
}


function setup() {
    createCanvas(500, 300);
    frameRate(1);
    useSound();
}


function soundSetup() { 
    orangeScream.setVolume(0.25);
    bananaScream.setVolume(0.25);
    redAppleScream.setVolume(0.25);
    greenAppleScream.setVolume(0.25);
}

function orange(x, y) {
    fill(255, 137, 0);
    noStroke();
    circle(x, y, 50);
}

function banana(x, y) {
    fill(255, 255, 0);
    noStroke();
    beginShape();
    curveVertex(x, y);
    curveVertex(x, y);
    curveVertex(x + 20, y + 45);
    curveVertex(x - 30, y + 80);
    curveVertex(x - 5, y + 45);
    curveVertex(x, y);
    curveVertex(x, y);
    endShape(CLOSE);
}

function apple(x, y) {
    noStroke();
    beginShape();
    curveVertex(x, y);
    curveVertex(x, y);
    curveVertex(x + 15, y - 10);
    curveVertex(x + 25, y);
    curveVertex(x + 20, y + 40);
    curveVertex(x, y + 30);
    curveVertex(x - 20, y + 40);
    curveVertex(x - 25, y);
    curveVertex(x - 15, y - 10);
    curveVertex(x, y);
    curveVertex(x, y);
    endShape(CLOSE);
}


function draw() {
    background(0, 0, 255);
    fill(205, 0, 255);
    noStroke();
    arc(250, 150, 300, 300, TWO_PI, PI, CHORD);
    //when a fruit disappears, it screams
    print(frameCount);
    if (frameCount <= 8) {
        orangeScream.play();
        orange(140 - dx, 140 - dy);
    } else if (frameCount <= 16) {
        bananaScream.play();
        banana(200 - dx, 90 - dy);
    } else if (frameCount <= 24) {
        redAppleScream.play();
        fill(255, 0, 0);
        apple(270 + dx, 120 - dy);
    } else {
        greenAppleScream.play();
        fill(0, 255, 0);
        apple(340 + dx, 120 - dy);
    }
    dx *= 2;
    dy *= 2;
}

Leave a Reply