{"id":66670,"date":"2021-09-27T02:41:24","date_gmt":"2021-09-27T06:41:24","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/?p=66670"},"modified":"2021-09-27T02:41:24","modified_gmt":"2021-09-27T06:41:24","slug":"project-4-string-art-10","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/2021\/09\/27\/project-4-string-art-10\/","title":{"rendered":"Project 4: 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=\"320\" data-height=\"240\" href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-content\/uploads\/2021\/09\/sketch-200.js\">Yash string art<\/a><iframe src=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-content\/plugins\/p5-embedder\/p5_iframe.html\" class=\"p5_exampleFrame\" width=\"\" height=\"240\"><\/iframe><pre class=\"language-javascript\"><code class=\"p5_editor language-javascript\">\/\/ Yash Mittal\n\/\/ Section D\n\nvar dx1;\nvar dy1;\nvar dx2;\nvar dy2;\nvar dx3;\nvar dy3;\nvar dx4;\nvar dy4;\nvar dx5;\nvar dy5;\nvar dx6;\nvar dy6;\n\nvar numLines = 30;\n\nfunction setup() {\n    createCanvas(400, 300);\n    background (0);\n    stroke (255);\n    line (70, 200, 180, 10); \/\/ reference line 1 \n    line (330, 180, 290, 70); \/\/ reference line 2\n    strokeWeight (0);\n    line (150, 290, 250, 260); \/\/ reference line 3\n    line (100, 100, 200, 200); \/\/ reference to line 4 \n    stroke (\"white\");\n    line (30, 70, 290, 110); \/\/ reference to line 5\n    strokeWeight (1);\n    line (20, 20, 110, 10); \/\/ reference to line 6\n\n\n    dx1 = (180 - 70) \/ numLines;\n    dy1 = (10 - 200) \/ numLines;\n    dx2 = (290 - 330) \/ numLines;\n    dy2 = (70 - 180) \/ numLines;\n    dx3 = (250 - 150) \/ numLines;\n    dy3 = (260 - 290) \/ numLines;\n    dx4 = (200 - 100) \/ numLines;\n    dy4 = (200 - 100) \/ numLines;\n    dx5 = (290 - 30) \/ numLines;\n    dy5 = (110 - 70) \/ numLines; \n    dx6 = (110 - 20) \/ numLines;\n    dy6 = (10 - 20) \/ numLines;\n\n}\n\nfunction draw() { \n\n    var x1 = 70;\n    var y1 = 200;\n    var x2 = 330;\n    var y2 = 180;\n    var x3 = 150;\n    var y3 = 290;\n    var x4 = 100; \n    var y4 = 200;\n    var x5 = 30;\n    var y5 = 290;\n    var x6 = 20;\n    var y6 = 20;\n    var x7 = 110;\n    var y7 = 10;\n\n    for (var i = 0; i &lt;= numLines; i = i + 0.9) { \/\/ center lines (left to right)\n\n        line (x1, y1, x2, y2);\n       \n        x2 = x2+ dx2;\n        y2 = y2 + dy2;\n        \n    }\n\n    stroke (\"yellow\");\n\n    for (var i2 = 0; i2 &lt;= numLines; i2 = i2 + 3) { \/\/ bottom lines (bottom left to top)\n\n        line (x2, y2, x3, y3);\n        x2 = x2 + dx3;\n        y2 = y2 + dy3;\n        x3 = x3 + dx3;\n        y3 = y3 + dy3;\n\n    }\n\n\n    stroke (\"white\");\n\n    for (var i5 = 0; i5 &lt;= numLines; i5 = i5 + 0.5) {\n\n        line (x4, y4, x5, y5);\n\n        x5 = x5 + dx5;\n        y5 = y5 + dy5;\n    }\n\n\n stroke (\"red\");\n\n    for (var i3 = 0; i3 &lt;= numLines; i3 = i3 + 1) { \/\/ top lines (top right to top center)\n\n        line (x2, y2, x1, y1);\n        x2 = x2 + dx3;\n        y2 = y2 + dy3;\n        x1 = x1 + dx1;\n        y1 = y1 + dy1;\n    }\n\n    for (var i4 = 0; i4 &lt;= numLines; i4 = i4 + 0.1) { \n\n        line (x3, y3, x2, y2);\n\n        x3 = x3 + dx3;\n        y3 = y3 + dy3;\n        x2 = x2 + dx2;\n        y2 = y2 + dy2;\n        \n}\n\n    stroke (\"yellow\");\n    strokeWeight (0.4);\n\n    for (var i6 = 0; i6 &lt;= numLines; i6 = i6 + 0.8) {\n\n        line (x1, y1, x3, y3);\n\n        x1 = x1 + dx1 \/ 2;\n        y1 = y1 + dx1 \/ 2;\n        x3 = x3 + dx3 \/ 2;\n        y3 = y3 + dy3 \/ 2;\n    }\n\n    stroke (\"red\");\n\n    for (var i7 = 0; i7 &lt;= numLines; i7 = i7 + 0.5) {\n\n        line (x6, y6, x4, y4);\n        x4 = x4 + dx4;\n        y4 = y4 + dy4;\n    }\n\n    strokeWeight (0.3);\n    stroke (\"red\");\n\n    for (var i8 = 0; i8 &lt;= numLines; i8 = i8 + 0.1) {\n\n        line (x7, y7, -x4, y4);\n        x7 = x7 + dx6;\n        y7 = y7 + dx6;\n       \n    }\n\nnoLoop();\n\n}<\/code><\/pre><\/p>  \n\n\n\n<p>I had fun working on this project. At first, I struggled to understand the mathematics behind the code but once I got the hang of it, it became pretty easy to draw new patterns on different parts of the canvas.<\/p><\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>Yash string art \/\/ Yash Mittal \/\/ Section D 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 numLines = 30; function setup() { createCanvas(400, 300); background (0); stroke (255); line (70, 200, 180, 10); \/\/ reference line 1 &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/2021\/09\/27\/project-4-string-art-10\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Project 4: String art&#8221;<\/span><\/a><\/p>\n","protected":false},"author":661,"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\/66670"}],"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\/661"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/comments?post=66670"}],"version-history":[{"count":4,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts\/66670\/revisions"}],"predecessor-version":[{"id":66676,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/posts\/66670\/revisions\/66676"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/media?parent=66670"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/categories?post=66670"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2021\/wp-json\/wp\/v2\/tags?post=66670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}