{"id":67676,"date":"2021-10-16T19:48:25","date_gmt":"2021-10-16T23:48:25","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/?p=67676"},"modified":"2021-10-16T19:48:51","modified_gmt":"2021-10-16T23:48:51","slug":"project-7-composition-with-curves","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/2021\/10\/16\/project-7-composition-with-curves\/","title":{"rendered":"Project-7: 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><a class=\"p5_sketch_link\" data-width=\"480\" data-height=\"480\" href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-content\/uploads\/2021\/10\/sketch-101.js\">My Project<\/a><iframe src=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/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\">\/\/cbtruong;\n\/\/Section B;\n\n\/\/sets up the variables for stroke color;\n\/\/col is the stroke color for smooth conical spiral;\n\/\/col2 is the stroke color for the rough conical spiral;\nvar col = 0;\nvar col2 = 0;\n\/\/sets up the variable for angl to allow for rotation;\nvar angl = 0;\n\/\/sets up the variable for the shifting fill color value;\n\/\/for the rough conical spiral;\nvar shiftingVal = 100;\n\/\/sets up the variable that allows for reversing the change;\n\/\/of shiftingVal;\nvar shiftingValChange = 1;\n\n\nfunction setup() {\n    createCanvas(480, 480);\n    background(220);\n    text(\"p5.js vers 0.9.0 test.\", 10, 15);\n}\n\nfunction draw() {\n    background(220);\n    stroke(0);\n    \/\/diagonal lines that hit the center of the spirals;\n    line(0, 0, 120, 120);\n    line(0, 480, 120, 360);\n    line(480, 0, 360, 120);\n    line(480, 480, 360, 360);\n    \/\/lines that outline the perimeter of the canvas;\n    line(0, 0, 480, 0);\n    line(0, 0, 0, 480);\n    line(480, 0, 480, 480);\n    line(0, 480, 480, 480);\n    \/\/lines of the innerbox whose vertices are the spiral centers;\n    line(120, 120, 120, 360);\n    line(120, 360, 360, 360);\n    line(360, 360, 360, 120);\n    line(360, 120, 120, 120);\n\n    \/\/draws the middle, rough concial spiral;\n    strokeWeight(2);\n    fill(shiftingVal);\n    stroke(col2);\n    push();\n    translate(240, 240);\n    conicalSpiralTopViewRough();\n    pop();\n    \n    \/\/draws the 4 smooth rotating conical spirals;\n    noFill();\n    stroke(col);\n    for (var i = 120; i &lt;= 360; i += 240){\n        for (var j = 120; j &lt;= 360; j += 240){\n            push();\n            translate(j, i);\n            rotate(radians(angl));\n            scale(0.5);\n            conicalSpiralTopViewSmooth();\n            pop();\n        }\n    }\n\n    \/\/checks if the shiftingVal is too high or low;\n    \/\/if too high, the fill becomes darker;\n    \/\/if too low, the fill becomes ligher;\n    if (shiftingVal &gt;= 255){\n        shiftingValChange = shiftingValChange * -1;\n    }\n    else if (shiftingVal &lt; 100){\n        shiftingValChange = shiftingValChange * -1;\n    }\n    \/\/changes the shiftingVal;\n    shiftingVal += 1*shiftingValChange;\n    \/\/changes the angle and allows for rotation;\n    \/\/of the smooth conical spirals;\n    angl += 0.1;\n    \n\n}\n\n\/\/function that creates the smooth conical spirals;\nfunction conicalSpiralTopViewSmooth() {\n    \/\/variables for h, height; a, angle; r, radius;\n    var h = 1;\n    var a;\n    var r = 30;\n    \n    \/\/adds interactivity;\n    \/\/as one goes right, the size of the spiral increases;\n    \/\/as one goes down, the complexity of the spiral increases;\n    var indepChangeX = map(mouseX, 0, 480, 500, 1000);\n    var indepChangeY = map(mouseY, 0, 480, 800, 1000);\n    a = indepChangeY;\n\n    \/\/actually creates the spiral;\n    beginShape();\n    for (var i = 0; i &lt; indepChangeX; i++){\n        var z = map(i, 0, 400, 0, PI);\n        x = ((h - z) \/ h)*r*cos(radians(a*z));\n        y = ((h - z) \/ h)*r*sin(radians(a*z));\n        vertex(x, y);\n    }\n    endShape(CLOSE);\n\n}\n\n\/\/function that creates the rough middle conical spiral;\nfunction conicalSpiralTopViewRough() {\n    \/\/variables are the same as the smoothSpiral function;\n    var h = 0.5;\n    var a = 1000;\n    var r;\n    \n    \/\/adds interactivity;\n    \/\/the radius is now dependant on mouseY, going up increases size;\n    \/\/going left increases complexity;\n    r = map(mouseY, 0, 480, 20, 10);\n    var edgeNum = map(mouseX, 0, 480, 60, 30);\n    \n    \/\/creates the spiral;\n    beginShape();\n    for (var i = 0; i &lt; edgeNum; i++){\n        var z = map(i, 0, 50, 0, TWO_PI);\n        x = ((h - z) \/ h)*r*cos(radians(a*z));\n        y = ((h - z) \/ h)*r*sin(radians(a*z));\n        vertex(x, y);\n    }\n    endShape();\n}\n\n\/\/mousePressed function that changes the variables col and col2;\n\/\/with random values of r, g, and b;\nfunction mousePressed() {\n    var randR = random(150);\n    var randG = random(150);\n    var randB = random(150);\n    col = color(randR, randG, randB);\n    col2 = color(randR + random(-50, 50), randG + random(-50, 50), randB + random(-50, 50));\n}\n\n<\/code><\/pre><\/p><p>\n\n\n\n<\/p><p>I initially had no idea what to make in terms of curves.  That was until I happened upon the <a rel=\"noreferrer noopener\" href=\"https:\/\/mathworld.wolfram.com\/ConicalSpiral.html\" data-type=\"URL\" data-id=\"https:\/\/mathworld.wolfram.com\/ConicalSpiral.html\" target=\"_blank\">Conical Spiral<\/a>.  It was supposed to be 3-D, but it ended up as a top down view of a spiral which I liked.  Overall, I liked what I did with this Project.<\/p>\n\n\n\n<p>As for how it works, clicking the mouse will change the colors of the middle &ldquo;rough&rdquo; Conical Spiral and the 4 &ldquo;smooth&rdquo; Conical Spirals.  The colors of both types are similar but not the same, as seen with the use of random() in the code.<\/p>\n\n\n\n<p>Along with that, moving the mouse right will increase the size of the &ldquo;smooth&rdquo; Spirals and reduce the size and complexity of the &ldquo;rough&rdquo; Spiral.   Moving left does the opposite.  Moving down increases the complexity of the &ldquo;smooth&rdquo; Spirals while also reducing the size of them and the &ldquo;rough&rdquo; Spiral.<\/p><\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>My Project \/\/cbtruong; \/\/Section B; \/\/sets up the variables for stroke color; \/\/col is the stroke color for smooth conical spiral; \/\/col2 is the stroke color for the rough conical spiral; var col = 0; var col2 = 0; \/\/sets up the variable for angl to allow for rotation; var angl = 0; \/\/sets up &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/2021\/10\/16\/project-7-composition-with-curves\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Project-7: Composition with Curves&#8221;<\/span><\/a><\/p>\n","protected":false},"author":675,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[108,56,1],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts\/67676"}],"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\/675"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/comments?post=67676"}],"version-history":[{"count":1,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts\/67676\/revisions"}],"predecessor-version":[{"id":67740,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts\/67676\/revisions\/67740"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/media?parent=67676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/categories?post=67676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/tags?post=67676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}