{"id":76078,"date":"2022-11-20T22:17:43","date_gmt":"2022-11-21T03:17:43","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/?p=76078"},"modified":"2022-11-20T22:17:43","modified_gmt":"2022-11-21T03:17:43","slug":"gondola-moment","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/11\/20\/gondola-moment\/","title":{"rendered":"gondola moment"},"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><a class=\"p5_sketch_link\" href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/11\/sketch-79.js\" data-width=\"400\" data-height=\"400\">sketch<\/a><iframe src=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/plugins\/p5-embedder\/p5_iframe.html\" class=\"p5_exampleFrame\" width=\"400\" height=\"400\"><\/iframe><pre class=\"language-javascript\"><code class=\"p5_editor language-javascript\">\/\/ jaden luscher\n\/\/ jluscher@andrew.cmu.edu\n\/\/ section a\n\/\/ project 11\n\n\/\/ this program draws a gondola ascending a mountain\n\/\/ populated by random cabins on a snowy slope\n\nvar hillheight = [];\nvar noiseParam = 0;\nvar noiseStep = 0.01;\nvar gondola;\nvar house = [];   \/\/ array of houses\nvar newhouseProbability = 0.01; \/\/ likelihood of a new house popping up per frame\n\nfunction preload() {\n    gondola = loadImage(\"https:\/\/i.imgur.com\/H4WC448.png\");\n    \/\/ gondola drawn in illustrator\n}\n\nfunction setup() {\n    createCanvas(400, 400);\n    frameRate(20);\n    noStroke();\n\n    \/\/ set up hill data\n    for (i = 0; i &lt;= width; i++) {\n        var n = noise(noiseParam);\n        var value = map(n, 0, 1, 50, 250);\n        hillheight.push(value);\n        noiseParam += noiseStep;\n    }\n\n    \/\/ first house\n    var onehouse = makehouse();\n    house.push(onehouse);\n}\n\n\nfunction draw() {\n    background(\"orange\");\n    drawMoon();\n\n    movehill();\n    drawhill();\n    drawslope();\n\n    for (var i = 0; i &lt; house.length; i++) {\n        movehouse(house[i]);\n        showhouse(house[i]);\n    }\n    if (house.length &gt; 0 & house[0].y - house[0].rh > height) {\n        \/\/ delete off-screen houses\n        house.shift();\n    }\n    if (newhouseProbability &gt; random(1.0)) {  \/\/ make new house randomly\n        var newhouse = makehouse();\n        house.push(newhouse);\n    }\n\n    push();\n    stroke(100);\n    strokeWeight(2);\n    line(0, 260, width, 40);\n    image(gondola, 170, 130, 100, 150);\n    pop();\n}\n\n\nfunction showhouse(h) {  \/\/ house x, y, width, height, roof height\n    push();\n    fill(200, 150, 100);\n    rect(h.x, h.y, h.w, h.h);\n    beginShape();\n    vertex(h.x - 2, h.y);\n    vertex(h.x + (h.w\/2), h.y - h.rh); \/\/ roof peak\n    vertex(h.x + h.w + 2, h.y);\n    endShape();\n    fill(230, 180, 120);\n    rect(h.x + h.w \/ 2 - 4, h.y + h.h, 8, -15); \/\/ door\n    pop();\n}\n\nfunction movehouse(h) {\n    h.x += h.dx;\n    h.y += h.dy;\n}\n\n\nfunction makehouse() {\n    var house = {x : width + 1,\n                y : random(120, 300),\n                w : random(15, 50),\n                h : random(15, 50),\n                rh : random(5, 20),\n                dx : -1,\n                dy : 0.55,\n                show : showhouse}\n    return house;\n}\n\n\nfunction movehill() {\n    hillheight.shift();   \/\/ creates scrolling effect\n    var n = noise(noiseParam);\n    var value = map(n, 0, 1, 50, 250);\n    hillheight.push(value);\n    noiseParam += noiseStep;\n}\n\n\/\/ background hills\nfunction drawhill() {\n    push();\n    fill(\"lightblue\")\n    beginShape();\n    for (var i = 0; i &lt; width +1; i++) {\n        var x = i;\n        vertex(x, hillheight[i]);\n    }\n    vertex(width, height);\n    vertex(0, height);\n    endShape(CLOSE);\n    pop();\n}\n\n\/\/ foreground white slope\nfunction drawslope() {\n    push();\n    fill(250);\n    beginShape();\n    vertex(width, height);\n    vertex(0, height);\n    vertex(0, 370);\n    vertex(width, 150);\n    endShape();\n    pop();\n}\n\nfunction drawMoon() {\n    fill(250);\n    ellipse(100, 80, 50, 50);\n    fill(\"orange\");\n    ellipse(105, 80, 45, 45);\n}\n<\/code><\/pre><\/div><\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>sketch \/\/ jaden luscher \/\/ jluscher@andrew.cmu.edu \/\/ section a \/\/ project 11 \/\/ this program draws a gondola ascending a mountain \/\/ populated by random cabins on a snowy slope var hillheight = []; var noiseParam = 0; var noiseStep = 0.01; var gondola; var house = []; \/\/ array of houses var newhouseProbability = &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/11\/20\/gondola-moment\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;gondola moment&#8221;<\/span><\/a><\/p>\n","protected":false},"author":741,"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\/76078"}],"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\/741"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/comments?post=76078"}],"version-history":[{"count":2,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/76078\/revisions"}],"predecessor-version":[{"id":76086,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/76078\/revisions\/76086"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/media?parent=76078"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/categories?post=76078"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/tags?post=76078"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}