{"id":75923,"date":"2022-11-20T00:48:38","date_gmt":"2022-11-20T05:48:38","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/?p=75923"},"modified":"2022-11-20T00:52:40","modified_gmt":"2022-11-20T05:52:40","slug":"project-11-airplane-and-parachute","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/11\/20\/project-11-airplane-and-parachute\/","title":{"rendered":"Project 11 \u2013 Airplane and parachute"},"content":{"rendered":"<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/REC-html40\/loose.dtd\">\n<html><body><div class=\"wp-block-file\"><a class=\"p5_sketch_link\" data-width=\"480\" data-height=\"480\" id=\"wp-block-file--media-7440d594-b381-4356-acd4-bf7ac716a063\" href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/sketch-69.js\">sketch<\/a><a href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/sketch-69.js\" class=\"wp-block-file__button\" download aria-describedby=\"wp-block-file--media-7440d594-b381-4356-acd4-bf7ac716a063\">Download<\/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\">\/* Jiayi Chen\n   jiayiche    Section A *\/\n\/\/arrays for display\nvar birds=[];\nvar clouds=[];\nvar flyObject =[];\n\n\/\/array for image storage\nvar birdsImg=[];\nvar cloudsImg=[];\nvar flyObjectImg =[];\n\/\/array for links\nvar cloudLinks = [\n    \"https:\/\/i.imgur.com\/suIXMup.png\",\n    \"https:\/\/i.imgur.com\/7ZHCI63.png\",\n    \"https:\/\/i.imgur.com\/EFb0w3u.png\",\n    \"https:\/\/i.imgur.com\/PxLKy41.png\"];\n\nvar birdLinks = [\n    \"https:\/\/i.imgur.com\/Gr1VTU5.png\",\n    \"https:\/\/i.imgur.com\/EmRp42l.png\",\n    \"https:\/\/i.imgur.com\/vLWSU4h.png\",\n    \"https:\/\/i.imgur.com\/Y9BecjA.png\"];\n\nvar flyObjectLink = [\n    \"https:\/\/i.imgur.com\/IXz53Lj.png\",\n    'https:\/\/i.imgur.com\/UsKzDwg.png'];\n\n\/\/load the images\nfunction preload(){\n    airplane = loadImage(\"https:\/\/i.imgur.com\/bEPeF8a.png\");\n    for (var i = 0; i &lt; cloudLinks.length; i++){\n        cloudsImg[i] = loadImage(cloudLinks[i]);\n    }\n    for (var i = 0; i &lt; birdLinks.length; i++){\n        birdsImg[i] = loadImage(birdLinks[i]);\n    }\n    for (var i = 0; i &lt; flyObjectLink.length; i++){\n        flyObjectImg[i] = loadImage(flyObjectLink[i]);\n    }\n}\n\nfunction setup() {\n    createCanvas(480, 480);\n    imageMode(CENTER);\n    \/\/initial clouds \n    for (var i = 0; i &lt; 3; i++){\n        var rc = floor(random(cloudsImg.length));\n        clouds[i] = makeCloud(random(width),random(100,300),random(height),cloudsImg[rc]);\n    }\n    frameRate(10);\n}\n\nfunction draw() {\n    background(135,206,235);\n    sun()\n    updateAndDisplayClouds();\n    addNewobjectsWithSomeRandomProbability();\n    removeObjectsThatHaveSlippedOutOfView();\n    image(airplane,200,constrain(250+random(-5,5),240,260),200,200);\n}\n\nfunction sun(){\n    push();\n    fill('orange');\n    circle(60,60,50);\n    fill('red');\n    circle(60,60,40);\n\n}\nfunction updateAndDisplayClouds(){\n    \/\/ Update the clouds's positions, and display them.\n    for (var i = 0; i &lt; clouds.length; i++){\n        clouds[i].move();\n        clouds[i].display();\n    }\n    \/\/ Update the birds's positions, and display them.\n    for (var i = 0; i &lt; birds.length; i++){\n        birds[i].move();\n        birds[i].display();\n    }\n    \/\/ Update the flyThings's positions, and display them.\n    for (var i = 0; i &lt; flyObject.length; i++){\n        flyObject[i].move();\n        flyObject[i].display();\n    }\n}\n\n\/\/remove out of sight things\nfunction removeObjectsThatHaveSlippedOutOfView(){\n    \/\/remove out of sight clouds\n    var cloudsToKeep = [];\n    for (var i = 0; i &lt; clouds.length; i++){\n        if (clouds[i].x + clouds[i].size\/2 &gt; 0) {\n            cloudsToKeep.push(clouds[i]);\n        }\n    }\n    clouds = cloudsToKeep; \/\/ remember the surviving clouds\n\n    \/\/remove out of sight birds\n    var birdsToKeep = [];\n    for (var i = 0; i &lt; birds.length; i++){\n        if (birds[i].x + birds[i].size\/2 &gt; 0){\n            birdsToKeep.push(birds[i]);\n        }\n    }\n    birds = birdsToKeep; \/\/ remember the surviving birds\n\n    \/\/remove out of sight fly things\n    var FlyesToKeep = [];\n    for (var i = 0; i &lt; flyObject.length; i++){\n        if (flyObject[i].x + flyObject[i].size\/2 &gt; 0) {\n             FlyesToKeep.push(flyObject[i]);\n        }\n    }\n    flyObject = FlyesToKeep; \/\/ remember the surviving fly things\n}\n\n\nfunction addNewobjectsWithSomeRandomProbability() {\n    \/\/ With a low probability, add a new clouds to the end.\n    var newCloudLikelihood = 0.02; \n    if (random(0,1) &lt; newCloudLikelihood) {\n        var rc = floor(random(cloudsImg.length));\n        clouds.push(makeCloud(width+75,random(100,150),random(height),cloudsImg[rc]));\n    }\n    \/\/ With a low probability, add a new birds to the end.\n    var newbirdLikelihood = 0.03; \n    if (random(0,1) &lt; newbirdLikelihood) {\n        var rc = floor(random(birdsImg.length));\n        clouds.push(makeBirds(width+30,random(30,60),random(height),floor(random(birdsImg.length))));\n    }\n    \/\/ With a low probability, add a new flying things to the end.\n    var newObejctLikelihood = 0.01; \n    if (random(0,1) &lt; newObejctLikelihood) {\n        var rc = floor(random(flyObjectImg.length));\n        clouds.push(makeFly(width+50,random(50,100),random(0,240),flyObjectImg[rc]));\n    }\n}\n\n\/\/make clouds as objects\nfunction makeCloud(birthLocationX,cs,ch,cloudCartoon) {\n    var cldg = {x: birthLocationX,\n                size: cs,\n                y:ch,\n                speed: -1.0,\n                cartoon:cloudCartoon,\n                move: cloudMove,\n                display: cloudDisplay}\n    return cldg;\n}\n\nfunction cloudMove() {\/\/move clouds\n    this.x += this.speed;\n}\n\nfunction cloudDisplay(){\n    image(this.cartoon, this.x, this.y,this.size, this.size); \n}\n\n\/\/make birds as objects\nfunction makeBirds(birthLocationX,cs,ch,birdCartoon) {\n    var mb = {x: birthLocationX,\n                size: cs,\n                y:ch,\n                speed: -3.0,\n                cartoonNumber:birdCartoon,\n                move: birdsMove,\n                display: birdsDisplay}\n    return mb;\n}\n\nfunction birdsMove() {\n    if(this.cartoonNumber == 0 || this.cartoonNumber == 1){\n        this.x += this.speed\/2;    \/\/birds facing to the left are flying slower\n        this.y += random(-3,3);    \/\/randomly fly\n    }else{\n        this.x += this.speed;\n        this.y += random(-5,5);    \/\/randomly fly\n    }\n\n}\n\nfunction birdsDisplay(){\n    image(birdsImg[this.cartoonNumber], this.x, this.y,this.size, this.size); \n}\n\n\/\/make other flying things as objects\nfunction makeFly(birthLocationX,cs,ch,flyCartoon) {\n    var mf = {x: birthLocationX,\n                size: cs,\n                y:ch,\n                speed: -2.0,\n                cartoon:flyCartoon,\n                move: flyMove,\n                display: flyDisplay}\n    return mf;\n}\n\nfunction flyMove() {\/\/move flying objects\n    this.x += this.speed;\n    \/\/gravity for things without wings\n    this.y -=this.speed\/4;\n}\n\nfunction flyDisplay(){\n    image(this.cartoon, this.x, this.y,this.size, this.size); \n}\n\n<\/code><\/pre><\/div><\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>sketchDownload \/* Jiayi Chen jiayiche Section A *\/ \/\/arrays for display var birds=[]; var clouds=[]; var flyObject =[]; \/\/array for image storage var birdsImg=[]; var cloudsImg=[]; var flyObjectImg =[]; \/\/array for links var cloudLinks = [ &#8220;https:\/\/i.imgur.com\/suIXMup.png&#8221;, &#8220;https:\/\/i.imgur.com\/7ZHCI63.png&#8221;, &#8220;https:\/\/i.imgur.com\/EFb0w3u.png&#8221;, &#8220;https:\/\/i.imgur.com\/PxLKy41.png&#8221;]; var birdLinks = [ &#8220;https:\/\/i.imgur.com\/Gr1VTU5.png&#8221;, &#8220;https:\/\/i.imgur.com\/EmRp42l.png&#8221;, &#8220;https:\/\/i.imgur.com\/vLWSU4h.png&#8221;, &#8220;https:\/\/i.imgur.com\/Y9BecjA.png&#8221;]; var flyObjectLink = [ &#8220;https:\/\/i.imgur.com\/IXz53Lj.png&#8221;, &#8216;https:\/\/i.imgur.com\/UsKzDwg.png&#8217;]; \/\/load &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/11\/20\/project-11-airplane-and-parachute\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Project 11 \u2013 Airplane and parachute&#8221;<\/span><\/a><\/p>\n","protected":false},"author":710,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[115,55],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/75923"}],"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\/710"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/comments?post=75923"}],"version-history":[{"count":3,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/75923\/revisions"}],"predecessor-version":[{"id":75929,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/75923\/revisions\/75929"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/media?parent=75923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/categories?post=75923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/tags?post=75923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}