{"id":74357,"date":"2022-10-14T18:23:40","date_gmt":"2022-10-14T22:23:40","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/?p=74357"},"modified":"2022-10-14T18:23:40","modified_gmt":"2022-10-14T22:23:40","slug":"project-07-srauch-curves","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/10\/14\/project-07-srauch-curves\/","title":{"rendered":"Project 07 &#8211; srauch &#8211; 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>Here is my program that runs on curves. I call it &ldquo;laser ballerinas&rdquo;. Move your mouse left to right to increase the size of the curves and the overall rotation, and move your mouse up and down to change the number of &ldquo;lobes&rdquo; on each curve. Click to change the colors of each lobe!<\/p>\n<div><a class=\"p5_sketch_link\" href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/10\/sketch-114.js\" data-width=\"400\" data-height=\"400\">sketch<\/a>\n\n\n\n<p><\/p><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\">\/\/Sam Rauch, section B, srauch@andrew.cmu.edu, project 07\n\/\/This code produces a \"laser ballerinas\" using epicycloid curves. Ten epicycloid curves of decreasing\n\/\/size and random colors are drawn on top of each other to produce \"nested curves\", and six nested curves\n\/\/are drawn in a hexagon pattern around the center of the canvas, which spins. MouseX controls the size of\n\/\/the curves and the rotation of the hexagon pattern, while mouseY controls the number of \"lobes\" produced\n\/\/in each epicycloid curve. Click to change the colors of the ballerinas!\n\nvar coloroptions;\n\nfunction setup() {\n    createCanvas(400, 400);\n    background(220);\n    text(\"p5.js vers 0.9.0 test.\", 10, 15);\n\n    coloroptions = [];\n    for (var i = 0; i &lt; 9; i++) {\n        coloroptions[i] = color(random(255), random(255), random(255));\n    }\n\n}\n\nfunction draw() {\n    background(0);\n    translate(width\/2, height\/2);\n    \n    \/\/create spin the hexagon of curves around the center of the canvas according to mouseX\n    push();\n    var spinamt = map(mouseX, 0, width, 0, 2*PI)\n    rotate(spinamt);\n\n\n    \/\/draws six nested curves in a hexagon pattern\n    for (var i = 0; i &lt; 6; i++){\n        push();\n        translate(100, 0);\n        nestedCurve();\n        pop();\n        rotate(radians(60));\n    }\n\n    pop();\n\n}\n\n\/\/generates epicycloid curve (https:\/\/mathworld.wolfram.com\/Epicycloid.html) with center at 0,0\nfunction drawCurve(color){ \n    \n    noFill();\n    stroke(color);\n    strokeCap(ROUND);\n    strokeJoin(ROUND);\n    strokeWeight(3);\n\n    var points = 80;\n    var xValues = [];\n    var yValues = [];\n    var a = mouseX\/4; \/\/radius of larger inner circle \n    var b = constrain(mouseY\/10, 0, a) ; \/\/40; \/\/radius of smaller outer circle\n    var theta = 0;\n\n    \/\/generating x and y values based on epicycloid curve forumla, and increasing the center angle\n    \/\/by a small amount\n    for (var i = 0; i &lt; points; i++) {\n        theta += radians(5);\n        xValues[i] = (a+b)*cos(theta) - b*cos(((a+b)\/b)*theta);\n        yValues[i] = (a+b)*sin(theta) - b*sin(((a+b)\/b)*theta);\n    }\n    \n    \/\/plotting x and y values\n    beginShape();\n    for (var i = 0; i &lt;points; i++) {\n        vertex(xValues[i], yValues[i]);\n    }\n    endShape();\n}\n\n\/\/draws ten epicycloid curves of random colors nested inside each other\nfunction nestedCurve() {\n    push();\n\n    var size = 1;\n    var sizeIncrement = 0.1;\n\n    \/\/draws ten epicycloid curves, but for each one, decreases scale and change color\n    for (var i = 0; i &lt; 9; i++) {\n        scale(size);\n\n        var col = coloroptions[i];\n        drawCurve(col);\n        size -= sizeIncrement;\n    }\n\n    pop();\n}\n\nfunction mousePressed(){\n    for (var i = 0; i &lt; 9; i++) {\n        coloroptions[i] = color(random(255), random(255), random(255));\n    }\n}<\/code><\/pre><\/div><\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>Here is my program that runs on curves. I call it &ldquo;laser ballerinas&rdquo;. Move your mouse left to right to increase the size of the curves and the overall rotation, and move your mouse up and down to change the number of &ldquo;lobes&rdquo; on each curve. Click to change the colors of each lobe! sketch &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/10\/14\/project-07-srauch-curves\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Project 07 &#8211; srauch &#8211; curves&#8221;<\/span><\/a><\/p>\n","protected":false},"author":754,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[108,56],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/74357"}],"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\/754"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/comments?post=74357"}],"version-history":[{"count":1,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/74357\/revisions"}],"predecessor-version":[{"id":74358,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/74357\/revisions\/74358"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/media?parent=74357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/categories?post=74357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/tags?post=74357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}