{"id":66681,"date":"2021-09-27T10:27:14","date_gmt":"2021-09-27T14:27:14","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/?p=66681"},"modified":"2021-09-27T10:27:14","modified_gmt":"2021-09-27T14:27:14","slug":"project-04-string-art-15","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/2021\/09\/27\/project-04-string-art-15\/","title":{"rendered":"Project 04- String Art"},"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=\"400\" data-height=\"300\" href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-content\/uploads\/2021\/09\/sketch-201.js\">sketch<\/a><iframe src=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-content\/plugins\/p5-embedder\/p5_iframe.html\" class=\"p5_exampleFrame\" width=\"400\" height=\"300\"><\/iframe><pre class=\"language-javascript\"><code class=\"p5_editor language-javascript\">\/\/Catherine Liu\n\/\/jianingl\n\/\/Section D\n\nvar strokeColorR = 255\nvar strokeColorG = 165\nvar strokeColorB = 0\n\nvar dx1;\nvar dy1;\nvar dx2;\nvar dy2;\n\nvar dx3;\nvar dy3;\nvar dx4;\nvar dy4;\n\nvar dx5;\nvar dy5;\nvar dx6;\nvar dy6;\n\nvar dx7;\nvar dy7;\nvar dx8;\nvar dy8;\n\nvar dx9;\nvar dy9;\nvar dx10;\nvar dy10;\n\nvar numLines = 50;\n\nfunction setup() {\n    createCanvas(400, 300);\n    background(0);\n\n    \/\/draws line that curves downward\n    line(0,0,width\/2,height);\n    line(width\/2,height,width,0);\n    dx1 = (width\/2-0)\/numLines;\n    dy1 = (height-0)\/numLines;\n    dx2 = (width-width\/2)\/numLines;\n    dy2 = (0-height)\/numLines;\n\n    \/\/draws line that curves upward\n    line(0,height,width\/2,0);\n    line(width\/2,0,width,height);\n    dx3 = (width\/2-0)\/numLines;\n    dy3 = (0-height)\/numLines;\n    dx4 = (width-width\/2)\/numLines;\n    dy4 = (height-0)\/numLines;\n\n    \/\/draws line that curves left\n    line(0,0,width,height\/2);\n    line(width,height\/2,0,height);\n    dx5 = (width-0)\/numLines;\n    dy5 = (height\/2-0)\/numLines;\n    dx6 = (0-width)\/numLines;\n    dy6 = (height-height\/2)\/numLines;\n\n    \/\/draws line that curves right\n    line(width,0,0,height\/2);\n    line(0,height\/2,width,height);\n    dx7 = (0-width)\/numLines;\n    dy7 = (height\/2-0)\/numLines;\n    dx8 = (width-0)\/numLines;\n    dy8 = (height-height\/2)\/numLines;\n}\n\nfunction draw() {\n    background(0);\n    stroke(strokeColorR, strokeColorG, strokeColorB);\n\n    \/\/draws line that curves downwards\n    var x1 = 0;\n    var y1 = 0;\n    var x2 = width\/2;\n    var y2 = height;\n    for (var i = 0; i &lt;= numLines; i += 1) {\n        line(x1, y1, x2, y2);\n        x1 += dx1;\n        y1 += dy1;\n        x2 += dx2;\n        y2 += dy2;\n    }\n\n    \/\/draws line that curves upward\n    var x3 = 0;\n    var y3 = height;\n    var x4 = width\/2;\n    var y4 = 0;\n    for (var i = 0; i &lt;= numLines; i += 1) {\n        line(x3, y3, x4, y4);\n        x3 += dx3;\n        y3 += dy3;\n        x4 += dx4;\n        y4 += dy4;\n    }\n\n    \/\/draws line that curves left\n    var x5 = 0;\n    var y5 = 0;\n    var x6 = width;\n    var y6 = height\/2;\n    for (var i = 0; i &lt;= numLines; i += 1) {\n        line(x5, y5, x6, y6);\n        x5 += dx5;\n        y5 += dy5;\n        x6 += dx6;\n        y6 += dy6;\n    }\n\n    \/\/draws line that curves right\n    var x7 = width;\n    var y7 = 0;\n    var x8 = 0;\n    var y8 = height\/2;\n    for (var i = 0; i &lt;= numLines; i += 1) {\n        line(x7, y7, x8, y8);\n        x7 += dx7;\n        y7 += dy7;\n        x8 += dx8;\n        y8 += dy8;\n    }\n}\n\nfunction mousePressed() {\n\n    \/\/checks for R value of color and switches\n    if (strokeColorR == 255) {\n        strokeColorR = 0\n    } else {\n        strokeColorR = 255\n    }\n\n    \/\/checks for G value of color and switches\n    if (strokeColorG == 165) {\n        strokeColorG = 191\n    } else {\n        strokeColorG = 165\n    }\n\n    \/\/checks for B value of color and switches\n    if (strokeColorB == 0) {\n        strokeColorB = 255\n    } else {\n        strokeColorB = 0\n    }\n}<\/code><\/pre><\/p>\n\n\n\n<p>It took me a while to figure out how to use the string to create patterns but once I had a good idea of what I wanted to create it was relatively easy to add strings. I also included the ability for the string to change color when you press the mouse.<\/p><\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>sketch \/\/Catherine Liu \/\/jianingl \/\/Section D var strokeColorR = 255 var strokeColorG = 165 var strokeColorB = 0 var dx1; var dy1; var dx2; var dy2; var dx3; var dy3; var dx4; var dy4; var dx5; var dy5; var dx6; var dy6; var dx7; var dy7; var dx8; var dy8; var dx9; var dy9; var &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/2021\/09\/27\/project-04-string-art-15\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Project 04- String Art&#8221;<\/span><\/a><\/p>\n","protected":false},"author":654,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[102,58],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts\/66681"}],"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\/654"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/comments?post=66681"}],"version-history":[{"count":2,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts\/66681\/revisions"}],"predecessor-version":[{"id":66684,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts\/66681\/revisions\/66684"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/media?parent=66681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/categories?post=66681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/tags?post=66681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}