{"id":1126,"date":"2021-09-22T13:35:51","date_gmt":"2021-09-22T17:35:51","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/?p=1126"},"modified":"2021-09-22T13:35:51","modified_gmt":"2021-09-22T17:35:51","slug":"aahdee-hatching","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/aahdee\/09\/22\/aahdee-hatching\/","title":{"rendered":"aahdee &#8211; Hatching"},"content":{"rendered":"<p>There&#8217;s two svgs as I used PEmbroider<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-1131\" src=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/outputletter.svg\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/\/2021\/09\/outputletter.svg 640w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/\/2021\/09\/outputletter.svg 27w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p><a href=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/emhatchprint.svg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-1132\" src=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/2021\/09\/emhatchprint.svg\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/\/2021\/09\/emhatchprint.svg 640w, https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-content\/uploads\/\/2021\/09\/emhatchprint.svg 27w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/a><\/p>\n<p>I used PEmbroider for the last one. This assignment was one of the easiest and the most fun for me. For the second one, I used some tiling techniques to ensure that I didn&#8217;t draw the same line twice. I also wrote the best switch statement of my life for that one. I used the techniques of ordered randomness for the third one to ensure that the crosses are balanced and gives an effect of increasing shading.<\/p>\n<p>The code is below the continue reading.<\/p>\n<p><!--more--><\/p>\n<pre>import processing.embroider.*;\r\nimport processing.svg.*;\r\nPEmbroiderGraphics E;\r\n\r\nint canvasSizeW = 1150;\r\nint canvasSizeH = 900;\r\n\r\nvoid settings() {\r\n  size(canvasSizeW, canvasSizeH);\r\n}\r\n\r\nvoid setup() {\r\n  noLoop();\r\n  surface.setLocation(50, 50);\r\n  E = new PEmbroiderGraphics(this, width, height);\r\n  \/\/beginRecord(SVG, \"hatch.svg\");\r\n  \/\/noFill();\r\n\r\n  String filePath = sketchPath(\"embroiderc.svg\");\r\n  E.setPath(filePath);\r\n  E.beginDraw();\r\n  E.clear();\r\n  E.strokeWeight(1);\r\n  E.fill(0, 0, 0);\r\n  E.noStroke();\r\n\r\n  E.toggleConnectingLines(false);\r\n  E.toggleResample(false);\r\n  \/\/E.rect(50,50,960,192);\r\n\r\n  MyVecField f = new MyVecField(); \r\n  E.HATCH_MODE = PEmbroiderGraphics.VECFIELD;\r\n  E.HATCH_VECFIELD = f;\r\n  \/\/E.HATCH_ANGLE = radians(90); \r\n  \/\/E.HATCH_ANGLE2 = radians(75); \r\n  int ew = 192;\r\n  for (int i = 0; i&lt; 5; i++) {\r\n    E.HATCH_SPACING = 25-i*5;\r\n    E.rect((ew)*i+50, 50, ew, ew);\r\n  }\r\n  \r\n\r\n\r\n  E.optimize(); \/\/ slow, but good and important\r\n  E.visualize();\r\n  E.endDraw(); \/\/ write out the file\r\n  \/\/background(220);\r\n  \r\n}\r\n\r\nclass MyVecField implements PEmbroiderGraphics.VectorField {\r\n  public PVector get(float x, float y) {\r\n    x*=0.05;\r\n    return new PVector(.5, 0.2*tan(2*x + 3));\r\n  }\r\n}\r\n\r\nvoid draw() {\r\n  \/\/\/\/hatch2(50, 50, 192);\r\n  \/\/hatch2(50, 50, 192);\r\n  \/\/rect(50, 50, 960,192);\r\n  \/\/hatch3(50, 262, 192);\r\n  \/\/rect(50, 262, 960,192);\r\n  \/\/hatch1(50, 474, 192);\r\n  \/\/rect(50, 474, 960,192);\r\n  \r\n  \/\/endRecord();\r\n  ;\r\n}\r\n\r\n\/\/ ----- HATCH 1 -----\r\n\r\nvoid hatch1(int x1, int y1, float w) {\r\n  int crossW = 3;\r\n  for (int i = 0; i &lt; 5; i++) {\r\n    float startX = (w)*i+x1;\r\n    float startY = y1;\r\n\r\n    \/\/square(startX, startY, w);\r\n    float fillPercent = 7*(10+ 20*i)\/10;\r\n    float fillSec = w\/fillPercent;\r\n\r\n    for (int j = 0; j &lt; fillPercent; j++) {\r\n      float row = j*(fillSec);\r\n      float rowOff = fillSec-crossW\/2;\r\n      for (int k = 0; k &lt; fillPercent; k++) {\r\n        float col = k*(fillSec);\r\n        float colOff = fillSec-crossW\/2;\r\n        float x = random(startX+row+(crossW\/2), startX+row+rowOff);\r\n        float y = random(startY+col+(crossW\/2), startY+col+colOff);\r\n        cross(x, y, crossW);\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n\r\nvoid cross(float x, float y, float size) {\r\n  line(x-size\/2, y-size\/2, x+size\/2, y+size\/2);\r\n  line(x-size\/2, y+size\/2, x+size\/2, y-size\/2);\r\n}\r\n\r\n\/\/ ----- HATCH 2 -----\r\n\r\nvoid hatch2(int x1, int y1, float w) {\r\n  for (int i = 0; i &lt; 5; i++) {\r\n    float startX = (w)*i+x1;\r\n    float startY = y1;\r\n\r\n    \/\/square(startX, startY, w);\r\n    float fillPercent = (10+ 20*i)\/2;\r\n    float fillSec = w\/fillPercent;\r\n    \/\/float partition = \r\n    for (int j = 0; j &lt;= fillPercent; j++) {\r\n      float row = j*(fillSec);\r\n      line(startX, startY+row, startX+row, startY);\r\n    }\r\n    for (int j = 0; j &lt; fillPercent; j++) {\r\n      float row = j*(fillSec);\r\n\r\n      line(startX+row, startY+w, startX+(row\/2), startY+w-(row\/2));\r\n    }\r\n    for (int j = 0; j &lt;= fillPercent; j++) {\r\n      float row = j*(fillSec);\r\n\r\n      line(startX+w, startY+row, startX+w-(row\/2), startY+(row\/2));\r\n    }\r\n    print(startX+w);\r\n    print(\"\\n\");\r\n  }\r\n}\r\n\r\n\/\/ ----- HATCH 3 -----\r\n\r\n\r\nvoid hatch3(int x1, int y1, float w) {\r\n  for (int i = 0; i &lt; 5; i++) {\r\n    float startX = (w)*i+x1;\r\n    float startY = y1;\r\n\r\n    \/\/square(startX, startY, w);\r\n    float fillPercent = 10;\r\n    float fillSec = w\/fillPercent;\r\n\r\n    for (int j = 0; j &lt; fillPercent; j++) {\r\n      float row = j*(fillSec);\r\n\r\n      for (int k = 0; k &lt; fillPercent; k++) {\r\n        float col = k*(fillSec);\r\n        pattern(startX+row, startY+col, fillSec, i);\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n\/\/ okay i ATE right here \r\nvoid pattern(float x, float y, float size, int percent) {\r\n  beginShape();\r\n  noFill();\r\n  switch (percent) {\r\n  case 4:\r\n    vertex(x+size, y);\r\n  case 3:\r\n    vertex(x, y);\r\n  case 2:\r\n    vertex(x+(size\/2), y+(size\/2));\r\n  case 1: \r\n    vertex(x+size, y);\r\n  case 0:\r\n    vertex(x+size, y+size);\r\n    vertex(x+(size\/2), y+(size\/2));\r\n    vertex(x, y+size);\r\n  }\r\n  endShape();\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>There&#8217;s two svgs as I used PEmbroider I used PEmbroider for the last one. This assignment was one of the easiest and the most fun for me. For the second one, I used some tiling techniques to ensure that I didn&#8217;t draw the same line twice. I also wrote the best switch statement of my &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/aahdee\/09\/22\/aahdee-hatching\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;aahdee &#8211; Hatching&#8221;<\/span><\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/posts\/1126"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/comments?post=1126"}],"version-history":[{"count":1,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/posts\/1126\/revisions"}],"predecessor-version":[{"id":1145,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/posts\/1126\/revisions\/1145"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/media?parent=1126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/categories?post=1126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-428\/f2021\/wp-json\/wp\/v2\/tags?post=1126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}