{"id":71449,"date":"2022-09-10T23:37:21","date_gmt":"2022-09-11T03:37:21","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/?p=71449"},"modified":"2022-09-18T00:13:16","modified_gmt":"2022-09-18T04:13:16","slug":"project-02-varibleface","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/09\/10\/project-02-varibleface\/","title":{"rendered":"Project-03-Dynamic-Drawing"},"content":{"rendered":"<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/REC-html40\/loose.dtd\">\n<html><body><figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-18-000034-1024x514.png\" alt=\"\" class=\"wp-image-72233\" width=\"631\" height=\"317\" srcset=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-18-000034-1024x514.png 1024w, https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-18-000034-300x151.png 300w, https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-18-000034-768x386.png 768w, https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-18-000034-1536x772.png 1536w, https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-18-000034-1200x603.png 1200w, https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-18-000034.png 1855w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\"><\/figure><p>I began this project by writing down my main actions for the animation and what conditions caused them to change. After I got one part working, I slowly added more conditions and commands, ensuring they worked before continuing. <\/p>\n\n\n\n<p>The animation starts with a simple circle of lines. The user can click on the screen to make the second row of lines appear. If the user clicks on the left half then the direction that the lines are drawn changes. Depending on the quadrant the user clicks in the number of rows and color will change.<\/p>\n\n\n\n<div><a class=\"p5_sketch_link\" href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/09\/sketch-299.js\" data-width=\"600\" data-height=\"450\">sketch<\/a><iframe src=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/plugins\/p5-embedder\/p5_iframe.html\" class=\"p5_exampleFrame\" width=\"600\" height=\"450\"><\/iframe><pre class=\"language-javascript\"><code class=\"p5_editor language-javascript\">\/\/ Emily Franco\n\/\/ efranco\n\/\/ Section C\n\n\/\/line distance from center\nvar fromCenter = 5;\n\n\/\/x and y positions of pts for lines\nvar ptX = 0;\nvar ptY = 0;\n\n\/\/default line length\nvar length = 5;\n\n\/\/current rotation degree\nvar deg = 0;\nvar rot = 5;\nvar dir = 1;\nvar degTwo = 0;\n\n\/\/tracks how many times mouse is clicked\nvar clicked = 0;\n\/\/tracks number of circle sets\nvar cirSet = 0;\n\n\/\/stores mouseX and mouseY when clicked \nvar mX =0;\nvar mY = 0;\n\n\/\/store previous tranlation to subtract from when new center is clicked\nvar transX;\nvar transY;\n\n\/\/num of rows around circle\nvar rows = 6; \n\n\/\/colors\nvar r = 255;\nvar g = 255;\nvar b = 0;\n\n\n\/\/color increment\nvar colorInt = 20;\n\nfunction setup() {\n    createCanvas(600, 450);\n    background(220);\n    text(\"p5.js vers 0.9.0 test.\", 10, 15);\n    frameRate (70);\n    background (\"black\");\n\n}\n\nfunction draw() {\n\t\/\/change origin to center of canvas\n\ttransX = width\/2;\n\ttransY = height\/2;\n\ttranslate (transX,transY);\n\t\n\t\/\/if mouse is clicke five times now center is \n\t\/\/at mouse position\n\tif (cirSet==1){\n\t\ttranslate (mX-transX,mY-transY);\n\t\ttransX = mX-transX;\n\t\ttransY = mY-transY;\n\t}\n\n\t\/\/only reset at start of each set\n\tif(clicked == rows){\n\t\t\/\/reset values\n\t\tfromCenter = 5;\n\t\tlength = 5;\n\t\tclicked = 0;\n\t}\n\n\tif (deg &lt;= 360){\n\t\t\/\/rotate lines\n\t\trotate (radians(deg));\n\t\tdeg += rot*dir;\n\n\t\t\/\/if mouse is in left half turn clockwise \n\t\t\/\/if mouse is in right hald turn counterclockwise\n\t\t\/\/draw lines towards center of canvas\n\t\tstroke (g,r,b);\n\t\tline (ptX+fromCenter,ptY,ptX+fromCenter+length,ptY);\n\t}\n\n\t\/\/line \"chases white lines\" and draws over them\n\tpush();\n\tstroke (b,g,r);\n\trotate (radians(degTwo));\n\tdegTwo += rot*dir;\n\tline (ptX+fromCenter,ptY,ptX+fromCenter+length,ptY);\n\t\/\/rect (ptX-1,ptY-length-fromCenter-1,2,length+2); \n\tpop();\n}\n\nfunction mousePressed (){\n\t\/\/increase distance of lines from center\n\tfromCenter += length + 10; \n\t\/\/increase length of lines\n\tlength+=10;\n\n\t\/\/if mouse clicked left of center draw counter clockwise\n\tif (mouseX&lt;=width\/2){\n\t\tdir = -1;\n\t}else if (mouseX&gt;=width\/2){\n\t\tdir = 1;\n\t}\n\n\t\/\/if circle is complete set degree back to zero\n\t\/\/this will let next row start where previous row ended for only white lines\n\tif (Math.abs(deg)&gt;=360){\n\t\tdeg = 0;  \n\t}\n\n\n\t\/\/add one to clicked each time mouse pressed\n\tclicked += 1;\n\t\n\t\/\/store x and y position for new center\n\tif (clicked==rows){\n\t\tcirSet = 1;\n\t\tmX = mouseX;\n\t\tmY = mouseY; \n\t}\n\n\t\/\/number of rows per circle changed on first click of each set\n\tif (clicked==1){\n\t\t\/\/number of rows per circle set changes in depending\n\t\t\/\/on the quadrant clicked in\n\t\tif (mouseX&lt;=width\/2 & mouseY<=height\/2){\n\t\t\t\trows = 3;\n\t\t\t\t\/\/blue\n\t\t\t\tr = 255;\n\t\t\t\tg = 0;\n\t\t\t\tb = 0;\n\t\t}if (mouseX&gt;=width\/2 & mouseY<=height\/2){\n\t\t\t\trows = 4;\n\t\t\t\t\/\/yellow\n\t\t\t\tr = 255;\n\t\t\t\tg = 255;\n\t\t\t\tb = 0;\n\t\t}if (mouseX&gt;=width\/2 & mouseY>=height\/2){\n\t\t\t\trows = 2;\n\t\t\t\t\/\/green\n\t\t\t\tr = 128;\n\t\t\t\tg = 255;\n\t\t\t\tb = 0;\n\t\t}if (mouseX&lt;=width\/2 & mouseY>=height\/2){\n\t\t\t\trows = 6;\n\t\t\t\t\/\/orange\n\t\t\t\tr = 255;\n\t\t\t\tg = 128;\n\t\t\t\tb = 0;\n\t\t\t\t\n\t\t}\n\t}\n\n}\n<\/code><\/pre><\/div><\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>I began this project by writing down my main actions for the animation and what conditions caused them to change. After I got one part working, I slowly added more conditions and commands, ensuring they worked before continuing. The animation starts with a simple circle of lines. The user can click on the screen to &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/09\/10\/project-02-varibleface\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Project-03-Dynamic-Drawing&#8221;<\/span><\/a><\/p>\n","protected":false},"author":719,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[100,57],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/71449"}],"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\/719"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/comments?post=71449"}],"version-history":[{"count":7,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/71449\/revisions"}],"predecessor-version":[{"id":72238,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/71449\/revisions\/72238"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/media?parent=71449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/categories?post=71449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/tags?post=71449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}