{"id":74481,"date":"2022-10-15T19:10:04","date_gmt":"2022-10-15T23:10:04","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/?p=74481"},"modified":"2022-10-15T19:10:04","modified_gmt":"2022-10-15T23:10:04","slug":"project-07-composition-with-curves","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/10\/15\/project-07-composition-with-curves\/","title":{"rendered":"Project 07 &#8211; Composition with Curves"},"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>Inspiration by Epicycloid Function<\/p>\n\n\n\n<div><a class=\"p5_sketch_link\" href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/10\/sketch-124.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\">\/\/Aarnav Patel\n\/\/aarnavp@andrew.cmu.edu\n\/\/Section D\n\/\/Project\n\nvar n = 1000;\nvar c;\n\nfunction setup() {\n    createCanvas(480, 480);\n    c = color(random(255), random(255), random(255));\n\n}\n\nfunction draw() {\n\tbackground(0);\n\tfor (var i = 0; i &lt; 3; i++) {\n\t\tdrawSpiral(i * width \/ 2);\t\t\t\/\/draws three times\n\t}\n\n}\n\nfunction mousePressed() {\n\tc = color(random(255), random(255), random(255));\n}\n\nfunction drawSpiral(w) {\n\tstroke(c);\n\tpush();\n\ttranslate(w, height \/ 2);\t\/\/Setting the origin\n\tnoFill();\n\tvar x;\n\tvar y;\n    var a = constrain(mouseX, 0, width);\t\t\n    var b = constrain(mouseY, 0, height);\t\t\/\/Constrains aim to keep proportional when mouse is in Canvas\n\n\t\n\tstrokeCap(ROUND);\n    strokeJoin(ROUND);\n    var t = 0;\n\n    beginShape();\t\t\t\t\t\/\/Starting shape before vertices inputted\n\tfor (var i = 0; i &lt; n; i++) {\t\t\t\t\t\t\t\n\t\tvar t = map(i, 0, n, 0, TWO_PI);\n\t\tx = (a + b) * cos(t) - b * cos((a + b \/ b) * t);\t\t\/\/Using the elipcycloid function for the x and y (cos and sin)\n\t\ty = (a + b) * sin(t) - b * sin((a + b \/ b) * t);\n\t\tvertex(x, y);\n\n\t}\n\tendShape();\t\t\t\t\t\/\/ending the shape\n\tpop();\t\t\t\t\t\t\/\/resetting for the next time its called\n\n}\n\n\n\n\n\/*\n\nfunction drawSpiral() {\n\t\/\/x\t=\t(a+b)cosphi-bcos((a+b)\/bphi)\n\n\t\/\/=\ta^2[cos(2theta)+\/-sqrt((b\/a)^4-sin^2(2theta))].\n\n\tnoStroke();\n\tvar a = mouseX \/ 4;\n\tvar b = 50;\n\n\tstrokeCap(ROUND);\n\tstrokeJoin(ROUND);\n\tvar t = 0;\n\tpush();\n\ttranslate(width \/ 2, height \/ 2);\n\tif (a &gt; b) {\n\t\t\/\/push();\n\t\tbeginShape();\n\t\tfor (var i = 0; i &lt; n; i++) {\n\t\t\tt = map(i, 0, n, 0, TWO_PI);\n\t\t\tvar r = sqrt(a * a * ( cos(t) + sqrt(pow((b \/ a), 4) - pow(sin(2 * t), 2))));\n\n\t\t\tvar x = r * cos(t);\n\t\t\tvar y = r * sin(t);\n\t\t\tconsole.log(x + \", \" + y)\n\n\t\t\tvertex (-x, y);\n\t\t}\n\t\tendShape();\n\t\t\/\/pop();\n\t}\n\t\t\n\t\/\/push();\n\tbeginShape();\n\tfor (var i = 0; i &lt; n; i++) {\n\t\tt = map(i, 0, n, 0, TWO_PI);\n\t\tvar r = sqrt(a * a * ( cos(t) + sqrt(pow((b \/ a), 4) - pow(sin(2 * t), 2))));\n\n\t\tvar x = r * cos(t);\n\t\tvar y = r * sin(t);\n\t\tconsole.log(x + \", \" + y)\n\n\t\tvertex(x, y);\n\t}\n\tendShape();\n\tpop();\n}\n*\/\n\n<\/code><\/pre><\/div><\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>Inspiration by Epicycloid Function sketch \/\/Aarnav Patel \/\/aarnavp@andrew.cmu.edu \/\/Section D \/\/Project var n = 1000; var c; function setup() { createCanvas(480, 480); c = color(random(255), random(255), random(255)); } function draw() { background(0); for (var i = 0; i &lt; 3; i++) { drawSpiral(i * width \/ 2); \/\/draws three times } } function mousePressed() { &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/10\/15\/project-07-composition-with-curves\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Project 07 &#8211; Composition with Curves&#8221;<\/span><\/a><\/p>\n","protected":false},"author":750,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[108,58],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/74481"}],"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\/750"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/comments?post=74481"}],"version-history":[{"count":3,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/74481\/revisions"}],"predecessor-version":[{"id":74484,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/74481\/revisions\/74484"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/media?parent=74481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/categories?post=74481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/tags?post=74481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}