{"id":75513,"date":"2022-11-12T13:54:26","date_gmt":"2022-11-12T18:54:26","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/?p=75513"},"modified":"2022-11-12T13:54:26","modified_gmt":"2022-11-12T18:54:26","slug":"project-10-sonic-story","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/11\/12\/project-10-sonic-story\/","title":{"rendered":"Project 10: Sonic Story"},"content":{"rendered":"<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/REC-html40\/loose.dtd\">\n<html><body><p>One Night on the Farm<br>One night on the farm, the farmer left the animals out. The crickets were chirping and the chickens were clucking. A whirring hum was heard and an alien space ship appeared. The alien first abducted the sheep who let out a surprised &ldquo;baa&rdquo; as he rose into the air and shrunk. The pig was next. He let out a startled &ldquo;oink&rdquo; as he was lifted away from his mud. Then it was the cows turn. He let out a shocked &ldquo;moo&rdquo; before being whisked away. The space ship left with its new specimens, and the crickets chirped and the chickens clucked some more.<\/p>\n\n\n\n<p>The farm images are licensed from Adobe stock images. The sounds used are from freesound.org and edited with Audacity. The sounds are used under the Creative Commons license. The owners did not want attribution. The sounds are: crickets.wav &ndash; crickets chirping, cluckcluck.wav &ndash; chickens clucking, spaceShip.wav &ndash; space ship sounds, moo.wav &ndash; a cow, baa.wav &ndash; a sheep, oink.wav &ndash; a pig.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" src=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/Farm.jpg\" alt=\"\" class=\"wp-image-75514\" width=\"315\" height=\"309\" srcset=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/Farm.jpg 737w, https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/Farm-300x294.jpg 300w\" sizes=\"(max-width: 315px) 85vw, 315px\"><\/figure><div><a class=\"p5_sketch_link\" href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/sketch-37.js\" data-width=\"480\" data-height=\"480\">sketch<\/a><iframe src=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/plugins\/p5-embedder\/p5_iframe.html\" class=\"p5_exampleFrame\" width=\"480\" height=\"480\"><\/iframe><pre class=\"language-javascript\"><code class=\"p5_editor language-javascript\">\/* Evan Stuhlfire\n * estuhlfi@andrew.cmu.edu Section B\n * Project-10:  Sonic Story - One Night on the Farm \nAssignment-10:  Sonic Story \nOne Night on the Farm \nOne night on the farm, the farmer left the animals \nout. The crickets were chirping and the chickens were\nclucking. A whiring hum was heard and an alien space ship appeared.\nThe alien first abducted the sheep who let out a surprised \"baa\" as he\nrose into the air and shrunk. The pig was next. He let out a startled\n\"oink\" as he was lifted away from his mud. Then it was the cows turn. \nHe let out a shocked \"moo\" before being whisked away. The \nspace ship left with its new specimens, and the crickets chirped\nand the chickens clucked some more.\n\nThe farm images are liscensed from Adobe stock images. The sounds used are from freesound.org and edited with Audacity.\nThe sounds are used under the Creative Commons liscense. The owners did not \nwant attribution. The sounds are:\ncrickets.wav - crickets chirping, cluckcluck.wav - chickens clucking,\nspaceShip.wav - space ship sounds, moo.wav - a cow, baa.wav - a sheep,\noink.wav - a pig.\n *\/\n\nvar farmImg = [];   \/\/ an array to store the images\nvar farmObjArray = []; \/\/ array to store images\n\n\/\/ sound variables\nvar crickets;\nvar cluck;\nvar baa;\nvar moo;\nvar oink;\nvar spaceShip;\n\n\/\/ starting sky and foreground colors\nvar rNight = 50;\nvar gNight = 100;\nvar bNight = 150;\nvar rFore = 50;\nvar gFore = 160;\nvar bFore = 80;\nvar moon = 100;\n\/\/ position of the moon\nvar xMoon;\nvar yMoon;\n\n\/\/ map to array indexes\nvar fence = 0;\nvar barn = 1;\nvar hay = 2;\nvar cow = 3;\nvar pig = 4;\nvar sheep = 5;\nvar chicken = 6; \nvar rooster = 7;\nvar ship = 8;\n\nfunction preload(){\n    \/\/ These URLs are images stored on imgur \n    \/\/ images liscensed from Adobe Stock images\n    \/\/ preload farm images\n    var filenames = [];\n    filenames[fence] = \"https:\/\/i.imgur.com\/bbBOrZ7.png\"; \n    filenames[barn] = \"https:\/\/i.imgur.com\/inS5Xdt.png\"; \n    filenames[hay] = \"https:\/\/i.imgur.com\/IXPEVak.png\"; \n    filenames[cow] = \"https:\/\/i.imgur.com\/8XjQyMt.png\"; \n    filenames[pig] = \"https:\/\/i.imgur.com\/7VPvVRB.png\"; \n    filenames[sheep] = \"https:\/\/i.imgur.com\/vIFlqDY.png\"; \n    filenames[chicken] = \"https:\/\/i.imgur.com\/vdTxUKf.png\"; \n    filenames[rooster] = \"https:\/\/i.imgur.com\/SCYoQoX.png\"; \n    filenames[ship] = \"https:\/\/i.imgur.com\/lAHddxj.png\"\n    \/\/ load farm images\n    for (var i = 0; i &lt; filenames.length; i++) {\n        farmImg[i] = loadImage(filenames[i]);\n    }\n\n    \/\/ load sounds\n    crickets = loadSound(\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/crickets2.wav\");\n    cluck = loadSound(\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/cluckcluck.wav\");\n    baa = loadSound(\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/baa.wav\");\n    moo = loadSound(\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/moo.wav\");\n    oink = loadSound(\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/oink.wav\");\n    spaceShip = loadSound(\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/spaceShip.wav\");\n\n}\n\nfunction stepImage() {\n    \/\/ \/\/ move and grow the space ship to get the sheep\n    if(this.imageNum == ship & this.moving) {\n        if(this.target == sheep) {\n            if(this.x < width\/4) {\n                this.x += this.speed;\n            }\n            if(this.y &lt; height\/2.5) {\n                this.y += this.speed;\n            }\n            if(this.ySize &lt;= 100) {\n                this.ySize += this.speed;\n            }\n            if(this.xSize &lt;= 200) {\n                this.xSize += this.speed;\n            } else {\n                if(this.drawBeam) {\n                    drawBeam(this.x, this.y, this.target); \n                }\n            }\n        } else if(this.target == pig) {\n            \/\/ move the space ship to get the pig\n            this.drawBeam = true; \/\/ turn the beam back on\n\n            if(this.ySize &gt;= 80) {\n                this.ySize -= this.speed;\n            }\n            if(this.xSize &gt;= 180) {\n                this.xSize -= this.speed;\n            }\n\n            if(this.y &gt; height\/3) {\n                this.y -= this.speed;\n            }\n            if(this.x &lt;= width\/2) {\n                this.x += this.speed;\n            } else {\n                if(this.drawBeam) {\n                    drawBeam(this.x, this.y, this.target); \n                }\n            }\n        } else if(this.target == cow) {\n            \/\/ move the space ship to get the cow\n            this.drawBeam = true; \/\/ turn the beam back on\n\n            if(this.ySize &lt;= 120) {\n                this.ySize += this.speed;\n            }\n            if(this.xSize &lt;= 240) {\n                this.xSize += this.speed;\n            }\n\n            if(this.y &lt; height\/1.8) {\n                this.y += this.speed;\n            }\n            if(this.x &gt;= width\/4) {\n                this.x -= this.speed;\n            } else {\n                \/\/ the ship is in the correct location for the beam\n                if(this.drawBeam) {\n                    drawBeam(this.x, this.y, this.target); \n                }\n            }\n        } else if(this.target &lt; cow) {\n            \/\/ fly away\n            if(this.ySize &gt;= 0) {\n                this.ySize -= this.speed;\n            }\n            if(this.xSize &gt;= 0) {\n                this.xSize -= this.speed;\n            }\n            if(this.y &gt; 0) {\n                this.y -= this.speed;\n            }\n            if(this.x &lt;= width) {\n                this.x += this.speed;\n            }\n        }\n    } \n\n    \/\/ when an animal is being abducted it shrinks and rises into the ship\n    if(this.imageNum == farmObjArray[ship].target & this.moving) {\n        \/\/ decrease y to rise into the ship\n        if(this.y >= farmObjArray[ship].y) {\n            this.y -= this.speed;\n        } else {\n            \/\/ turn the beam off and set target to pig\n            farmObjArray[ship].drawBeam = false;\n\n            \/\/ don't decrease the target below the cow index\n            if(farmObjArray[ship].target &gt;= cow) {\n                farmObjArray[ship].target--;\n            }\n            \n            \/\/ stop drawing this image\n            this.moving = false;\n            this.drawOn = false;\n        }\n        \n        \/\/ shrink\n        if(this.xSize &gt; 0) {\n            this.xSize *= .95;\n        }\n        if (this.ySize &gt; 0) {\n            this.ySize *= .95;\n        } \n        if(this.imageNum == sheep & frameCount % 15 == 0) {\n            baa.play();\n        } else if(this.imageNum == pig & frameCount % 15 == 0) {\n            oink.play();\n        } else if(this.imageNum == cow & frameCount % 12 == 0) {\n            moo.play();\n        }\n\n    }\n}\n\nfunction drawImage() {\n    \/\/ draw image\n    if(this.drawOn){\n       image(farmImg[this.imageNum], this.x, this.y, this.xSize, this.ySize);\n    } \n}\n\n\/\/ Constructor for each farm image\nfunction makeObj(cx, cy, imNum, xs, ys) {\n    var c = {x: cx, y: cy, xSize: xs, ySize: ys, \n             imageNum: imNum,\n             moving: false,\n             drawBeam: true,\n             target: sheep,\n             speed: 5,\n             drawOn: true,\n             stepFunction: stepImage,\n             drawFunction: drawImage\n         }\n    return c;\n}\n\nfunction setup() {\n    createCanvas(480, 480);\n    \/\/ set farm colors\n    background(rNight, gNight, bNight);\n    foreground(rFore, gFore, bFore);\n    \/\/ set initial moon position\n    xMoon = width + 25;\n    yMoon = height\/2.25;\n    xShip = width\/4;\n    yShip = height\/2 + 50;\n\n    imageMode(CENTER);\n    \/\/ create array of farm objects\n    createFarmObjs(); \n\n    frameRate(10);\n    useSound();\n}\n\nfunction soundSetup() { \/\/ setup for audio generation\n    crickets.setVolume(0.1);\n    cluck.setVolume(0.3);\n    baa.setVolume(0.3);\n    moo.setVolume(0.5);\n    oink.setVolume(0.3);\n    spaceShip.setVolume(0.5);\n}\n\nfunction draw() {\n    noStroke();\n    background(rNight, gNight, bNight);\n    foreground(rFore, gFore, bFore);\n    makeSounds();\n\n    var currentImage;\n    \/\/ loop over farm images and draw them\n    for(var i = 0; i &lt; farmObjArray.length; i++) {\n        currentImage = farmObjArray[i];\n        \/\/ draw the farm\n        currentImage.stepFunction();\n        currentImage.drawFunction();\n    }\n\n    \/\/ darken to night sky\n    fadeNightSky();        \n\n}\n\nfunction makeSounds() {\n    \/\/ make sounds at frameCount intervals\n    \/\/ play crickets\n    if(frameCount &gt;5 & frameCount < 350 && frameCount % 25 == 0) {\n        crickets.play();\n    } \n    \/\/ play cluck cluck\n    if ((frameCount &gt; 24 & frameCount < 350 && frameCount % 50 == 0)) {\n        cluck.play();\n    }\n    if(frameCount &gt; 24 & frameCount < 200 && frameCount % 25 == 0) {\n        spaceShip.play();\n    }\n\n    if(frameCount &gt; 400){\n        \/\/ stop all sounds\n        crickets.stop();\n        cluck.stop();\n        spaceShip.stop();\n        baa.stop();\n        moo.stop();\n        oink.stop();\n\n        \/\/ stop looping\n        noLoop();\n    }\n}\n\nfunction createFarmObjs() {\n    \/\/ create objects for farm: fence, barn, hay\n    \/\/ set initial positions xPos and yPos\n    var xPos = width\/1.25;\n    var yPos = height\/2;\n\n    \/\/ set initial size\n    var xs = 125;\n    var ys = 125;\n\n    \/\/ create farm objects\n    farmObjArray[fence] = makeObj(width\/2, yPos + 20, fence, xs * 5, \n        ys * .25);\n    farmObjArray[barn] = makeObj(xPos, yPos, barn, xs, ys);\n    farmObjArray[hay] = makeObj(xPos + 50, yPos + 50, hay, xs\/2, ys\/2);\n    farmObjArray[cow] = makeObj(width\/4, height\/1.2, cow, 100, 70);\n    farmObjArray[pig] = makeObj(width\/2, height\/1.68, pig, 55, 45);\n    farmObjArray[sheep] = makeObj(width\/4, height\/1.65, sheep, 30, 50);\n    farmObjArray[chicken] = makeObj(width\/1.2, height\/1.35, \n        chicken, 25, 35);\n    farmObjArray[rooster] = makeObj(width\/1.3, height\/1.45, \n        rooster, 30, 40);\n    farmObjArray[ship] = makeObj(0, height\/8, ship, 20, 1);\n}\n\nfunction drawBeam(x, y, target) {\n    \/\/ draw beam\n    fill(240, 250, 240, 80);\n    triangle(x, y, x + 65,\n        farmObjArray[target].y + 40, \n        x - 65,\n        farmObjArray[target].y + 40);\n\n    \/\/ set target to moving\n    farmObjArray[target].moving = true;\n}\n\nfunction fadeNightSky() {\n    \/\/ decrease the background colors to darken the sky to night\n    var offset = 5;\n    rNight -= offset;\n    gNight -= offset;\n    bNight -= offset;\n    rNight = max(0, rNight);\n    gNight = max(0, gNight);\n    bNight = max(0, bNight);\n\n    \/\/ draw moon\n    if(rNight == 0) {\n        fill(moon);\n        ellipse(xMoon, yMoon, 50);\n        moon++;\n        moon = min(moon, 245);  \n        xMoon -= offset;\n        yMoon -= offset;\n        xMoon = max(width\/1.35, xMoon);\n        yMoon = max(height\/7.75, yMoon);\n    }\n\n    \/\/ when it is dark start moving space ship\n    if(bNight == 0) {\n          farmObjArray[ship].moving = true;\n    }\n}\n\nfunction foreground(r, g, b) {\n    \/\/ create lawn and mud puddle for pig\n    fill(r, g, b);\n    rect(0, height\/2, width, height\/2);\n\n    fill(90, 80, 15);\n    ellipse(width\/2 - 10, height\/1.6, 150, 25);\n}\n<\/code><\/pre><\/div><\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>One Night on the FarmOne night on the farm, the farmer left the animals out. The crickets were chirping and the chickens were clucking. A whirring hum was heard and an alien space ship appeared. The alien first abducted the sheep who let out a surprised &ldquo;baa&rdquo; as he rose into the air and shrunk. &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/11\/12\/project-10-sonic-story\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Project 10: Sonic Story&#8221;<\/span><\/a><\/p>\n","protected":false},"author":760,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[113,56,1],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/75513"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/users\/760"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/comments?post=75513"}],"version-history":[{"count":4,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/75513\/revisions"}],"predecessor-version":[{"id":75536,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/75513\/revisions\/75536"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/media?parent=75513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/categories?post=75513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/tags?post=75513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}