{"id":65568,"date":"2021-09-11T18:26:14","date_gmt":"2021-09-11T22:26:14","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/?p=65568"},"modified":"2021-09-11T18:31:29","modified_gmt":"2021-09-11T22:31:29","slug":"project-2-variable-faces-6","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/2021\/09\/11\/project-2-variable-faces-6\/","title":{"rendered":"Project 2: Variable faces"},"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><a class=\"p5_sketch_link\" data-width=\"640\" data-height=\"640\" href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-content\/uploads\/2021\/09\/sketch-95.js\">sketch<\/a><a href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-content\/uploads\/2021\/09\/sketch-95.js\">Yash-variable faces<\/a><iframe src=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-content\/plugins\/p5-embedder\/p5_iframe.html\" class=\"p5_exampleFrame\" width=\"640\" height=\"640\"><\/iframe><pre class=\"language-javascript\"><code class=\"p5_editor language-javascript\">\/\/Simple beginning template for variable face\nvar eyeSize = 40;\nvar faceWidth = 400;\nvar faceHeight = 400;\nvar noseWidth = 3;\nvar mouth = 1;\nvar hair = 1;\nvar body = 100;\n\n\nfunction setup() {\n    createCanvas(640, 480);\n}\n \nfunction draw() {\n\n   background (250);\n\n    fill (239, 230, 131); \/\/ hands fill\n    ellipse (200, 320, 50, 50); \/\/ right hand\n    ellipse (440, 320, 50, 50); \/\/ left hand\n\n    fill (255, 153, 52); \/\/ body fill \n    ellipse (width \/ 2, height \/ 2 + 100, body, body + 50); \/\/ body\n\n    fill (107, 183, 216);\n\n   ellipse(width \/ 2, height \/ 2, faceWidth,  faceHeight); \/\/ face shape\n\n   fill ( 0, 0, 0 );\n   stroke (254, 211, 66);\n   strokeWeight (2);\n\n    var eyeLX = (width \/ 2 - faceWidth * 0.25); \n    var eyeRX = (width \/ 2 + faceWidth * 0.25);\n    ellipse(eyeLX, height \/ 2, eyeSize, eyeSize);\n    ellipse(eyeRX, height \/ 2, eyeSize, eyeSize);\n\n    stroke ( 0, 0, 0); \n    strokeWeight(1);\n    fill( 228, 129, 203 );\n\n   if (mouth &lt; 0.33) { \/\/ rect mouth\n        rect ( width \/ 2 - 10, height \/ 2 + 30, 40, 20 );\n\n   } else if ( mouth &lt; 0.66 ) { \/\/ line mouth\n        line (( width \/ 2 - 20 ),( height \/ 2 +30 ), ( width \/ 2 + 30 ),( height \/ 2 +40));\n\n   } else if ( mouth &lt; 1 ) {  \/\/ ellipse mouth\n        ellipse ( width \/ 2, height \/ 2 + 30, faceWidth \/ 2, faceHeight \/ 8);\n\n   }\n\n    fill (49, 50, 52);\n    strokeWeight (1);\n\n    if (noseWidth &lt;= 1) { \/\/ nose 1\n        triangle (width \/ 2, height \/ 2, width \/ 2 + 10, height \/ 2, width \/ 2 + 5, height \/ 2 + 10);\n\n    } else if (noseWidth &lt;=2) { \/\/ nose 2\n        triangle (width \/ 2 - 5, height \/ 2  + 3, width \/ 2 + 8, height \/ 2 + 1, width \/ 2 + 3, height \/ 2 + 16);\n\n    } else if (noseWidth &lt;=3) { \/\/ nose 3\n        triangle (width \/ 2 - 5, height \/ 2 +5, width \/ 2 + 6, height \/ 2 + 2, width \/ 2 + 15, height \/ 2 + 7); \n\n    }\n\n    \n}\n\nfunction mousePressed() {\n    \/\/ when the user clicks, these variables are reassigned\n    \/\/ to random values within specified ranges. For example,\n    \/\/ 'faceWidth' gets a random value between 75 and 150.\n    faceWidth = random(75, 350);\n    faceHeight = random(100, 250);\n    eyeSize = random(10, 30);\n    mouth = random(0,1);\n    noseWidth = random(0,3);\n    body = random (200, 250);\n}\n<\/code><\/pre><\/p>\n\n\n\n<p>I struggled with understanding how to manipulate variables in a randomized order but I had fun writing this code as it was satisfying to see it actually work at the end.<\/p><\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>sketchYash-variable faces \/\/Simple beginning template for variable face var eyeSize = 40; var faceWidth = 400; var faceHeight = 400; var noseWidth = 3; var mouth = 1; var hair = 1; var body = 100; function setup() { createCanvas(640, 480); } function draw() { background (250); fill (239, 230, 131); \/\/ hands fill ellipse &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/2021\/09\/11\/project-2-variable-faces-6\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Project 2: Variable faces&#8221;<\/span><\/a><\/p>\n","protected":false},"author":661,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[97,58],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts\/65568"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/users\/661"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/comments?post=65568"}],"version-history":[{"count":4,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts\/65568\/revisions"}],"predecessor-version":[{"id":65574,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts\/65568\/revisions\/65574"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/media?parent=65568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/categories?post=65568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/tags?post=65568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}