{"id":72669,"date":"2022-09-24T13:26:21","date_gmt":"2022-09-24T17:26:21","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/?p=72669"},"modified":"2022-09-24T13:26:21","modified_gmt":"2022-09-24T17:26:21","slug":"project-04-string-art-srauch","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/09\/24\/project-04-string-art-srauch\/","title":{"rendered":"Project 04 &#8211; String Art &#8211; srauch"},"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&rsquo;s my string art &mdash; when the mouse is pressed, it makes rainbow spiderwebs in each corner of the canvas. To erase the canvas and start over, press &ldquo;e&rdquo;. <\/p>\n<div><a class=\"p5_sketch_link\" href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-content\/uploads\/2022\/09\/sketch-335.js\" data-width=\"400\" data-height=\"300\">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=\"300\"><\/iframe><pre class=\"language-javascript\"><code class=\"p5_editor language-javascript\">\/\/Sam Rauch \/ srauch \/ section B\n\/\/this code generates four \"rainbow spiderwebs\", one in each corner of the canvas,\n\/\/as long as the mouse is pressed. When the user presses the \"e\" key, the canvas\n\/\/erases. \n\n\/\/ two points of A line\nvar ax1;\nvar ay1;\nvar ax2;\nvar ay2;\n\n\/\/ two points of B line\nvar bx1;\nvar by1;\nvar bx2;\nvar by2;\n\n\/\/ endpoints of connecting lines\nvar x1; \nvar y1;\nvar x2; \nvar y2;\n\n\nfunction setup() {\n    createCanvas(400, 300);\n    background(0);\n    text(\"p5.js vers 0.9.0 test.\", 10, 15);\n}\n\nfunction draw() {\n\n    \/\/draw spiderwebs in each quadrant of the canvas as long as mouse is pressed\n    if (mouseIsPressed){\n        strokeWeight(1);\n\n        stringart();\n\n        push();\n        translate(200,0);\n        stringart();\n        pop();\n\n        push();\n        translate(200,150);\n        stringart();\n        pop();\n\n        push();\n        translate(0, 150);\n        stringart();\n        pop();\n    }\n\n    \/\/erase canvas when user presses e key\n    if (keyIsPressed){\n        if (key == \"e\") {\n            background(0);\n        }\n    }\n}\n\n\/\/creates two lines, with 50 \"stringers\" between each line\nfunction stringart() {\n    \/\/canvas size (200, 150)\n\n    \/\/randomly generate location of A line\n    ax1 = random(10, 190);\n    ay1 = random(10, 140);\n    ax2 = random(10, 190);\n    ay2 = random(10, 140);\n\n    \/\/randomly generate location of B line\n    bx1 = random(10, 190);\n    by1 = random(10, 140);\n    bx2 = random(10, 190);\n    by2 = random(10, 140);\n\n    \/\/assign first stringer's location connecting top of A and bottom of B\n    x1 = ax1; \n    y1 = ay1;\n    x2 = bx2;\n    y2 = by2;\n\n    \/\/draw A line and B line in a random color\n    stroke(random(255), random(255), random(255));\n    line(ax1, ay1, ax2, ay2);\n    line(bx1, by1, bx2, by2);\n    strokeWeight(0.5);\n\n    \/\/draw 50 lines between A line and B line, incrementing 1\/50th of distance between x values\n    \/\/and y values of each line\n    for (var i = 0; i &lt; 51; i+=1) {\n\n        var x1Increment = (ax2- ax1) \/ 50;\n        var y1Increment = (ay2 - ay1) \/ 50;\n        var x2Increment = (bx1 - bx2) \/ 50;\n        var y2Increment = (by1 - by2) \/ 50;\n\n        \/\/first stringer\n        line (x1, y1, x2, y2);\n\n        \/\/changing position of stringer for each loop\n        x1 += x1Increment;\n        y1 += y1Increment;\n        x2 += x2Increment;\n        y2 += y2Increment;\n\n    }\n\n}<\/code><\/pre><\/div><\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>Here&rsquo;s my string art &mdash; when the mouse is pressed, it makes rainbow spiderwebs in each corner of the canvas. To erase the canvas and start over, press &ldquo;e&rdquo;. sketch \/\/Sam Rauch \/ srauch \/ section B \/\/this code generates four &#8220;rainbow spiderwebs&#8221;, one in each corner of the canvas, \/\/as long as the mouse &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/2022\/09\/24\/project-04-string-art-srauch\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Project 04 &#8211; String Art &#8211; srauch&#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":[102,56],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/72669"}],"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=72669"}],"version-history":[{"count":1,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/72669\/revisions"}],"predecessor-version":[{"id":72670,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/posts\/72669\/revisions\/72670"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/media?parent=72669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/categories?post=72669"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/15-104\/f2022\/wp-json\/wp\/v2\/tags?post=72669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}