{"id":241,"date":"2015-06-22T15:23:26","date_gmt":"2015-06-22T11:23:26","guid":{"rendered":"http:\/\/courses.haigarmen.com\/creativecoding\/?p=241"},"modified":"2015-06-22T15:23:26","modified_gmt":"2015-06-22T11:23:26","slug":"exercise-54","status":"publish","type":"post","link":"https:\/\/courses.haigarmen.com\/creativecoding\/exercise-54\/","title":{"rendered":"Exercise 54"},"content":{"rendered":"<pre><code>\r\n\/\/ P_2_1_3_02.pde\r\n\/\/ \r\n\/\/ Generative Gestaltung, ISBN: 978-3-87439-759-9\r\n\/\/ First Edition, Hermann Schmidt, Mainz, 2009\r\n\/\/ Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni\r\n\/\/ Copyright 2009 Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni\r\n\/\/\r\n\/\/ http:\/\/www.generative-gestaltung.de\r\n\/**\r\n * draw a module made of lines in a grid\r\n * \t \r\n * MOUSE\r\n * position x          : number of tiles horizontally\r\n * position y          : number of tiles vertically\r\n * \r\n * KEYS\r\n * 1-3                 : draw mode\r\n * s                   : save png\r\n * p                   : save pdf\r\n *\/\r\n\r\n\r\nimport processing.pdf.*;\r\nimport java.util.Calendar;\r\n\r\nboolean savePDF = false;\r\n\r\nfloat tileCountX = 5;\r\nfloat tileCountY = 5;\r\n\r\nint count = 10;\r\nint colorStep = 20;\r\n\r\nint lineWeight = 0;\r\nint strokeColor = 0;\r\n\r\ncolor backgroundColor = 0;\r\n\r\nint drawMode = 1;\r\n\r\nvoid setup() { \r\n  size(600, 600);\r\n} \r\n\r\nvoid draw() { \r\n  if (savePDF) beginRecord(PDF, timestamp()+\".pdf\");\r\n\r\n  colorMode(HSB, 360, 100, 100); \r\n  smooth();\r\n  strokeWeight(0.5);\r\n  strokeCap(ROUND);\r\n\r\n  tileCountX = mouseX\/30+1;\r\n  tileCountY = mouseY\/30+1;\r\n\r\n  background(backgroundColor);\r\n\r\n  for (int gridY=0; gridY<= tileCountY; gridY++) {\r\n    for (int gridX=0; gridX<= tileCountX; gridX++) {  \r\n\r\n      float tileWidth = width\/tileCountX;\r\n      float tileHeight = height\/tileCountY;\r\n      float posX = tileWidth*gridX;\r\n      float posY = tileHeight*gridY;\r\n\r\n      float x1 = tileWidth\/2;\r\n      float y1 = tileHeight\/2;\r\n      float x2 = 0;\r\n      float y2 = 0;\r\n\r\n      pushMatrix();\r\n      translate(posX, posY);\r\n\r\n      for(int side = 0; side < 4; side++) {\r\n        for(int i=0; i< count; i++) {\r\n\r\n           \/\/ move end point around the four sides of the tile\r\n          if(side == 0){     \r\n            x2 += tileWidth\/count;\r\n            y2 = 0;\r\n          }\r\n          if(side == 1){     \r\n            x2 = tileWidth;\r\n            y2 += tileHeight\/count;\r\n          }\r\n          if(side == 2){     \r\n            x2 -= tileWidth\/count;\r\n            y2 = tileHeight;\r\n          }\r\n          if(side == 3){     \r\n            x2 = 0;\r\n            y2 -= tileHeight\/count;\r\n          }\r\n\r\n          \/\/ adjust weight and color of the line\r\n          if(i < count\/2){\r\n            lineWeight += 1;\r\n            strokeColor += 60;\r\n          } \r\n          else {\r\n            lineWeight -= 1;\r\n            strokeColor -= 60;\r\n          }\r\n\r\n          \/\/ set colors depending on draw mode\r\n          switch(drawMode){\r\n          case 1:\r\n            backgroundColor = 360;\r\n            stroke(0);\r\n            break;\r\n          case 2:\r\n            backgroundColor = 360;\r\n            stroke(0);\r\n            strokeWeight(lineWeight);\r\n            break;\r\n          case 3:\r\n            backgroundColor = 0;\r\n            stroke(strokeColor);\r\n            strokeWeight(mouseX\/100);\r\n            break;\r\n          }\r\n\r\n          \/\/ draw the line\r\n          line(x1, y1, x2, y2);\r\n        }\r\n      }\r\n\r\n      popMatrix();\r\n    }\r\n  }\r\n\r\n  if (savePDF) {\r\n    savePDF = false;\r\n    endRecord();\r\n  }\r\n} \r\n\r\n\r\nvoid keyPressed() {\r\n  if (key == 's' || key == 'S') saveFrame(timestamp()+\"_##.png\");\r\n  if (key == 'p' || key == 'P') savePDF = true;\r\n\r\n  if (key == '1') drawMode = 1;\r\n  if (key == '2') drawMode = 2;\r\n  if (key == '3') drawMode = 3;\r\n}\r\n\r\n\r\n\/\/ timestamp\r\nString timestamp() {\r\n  Calendar now = Calendar.getInstance();\r\n  return String.format(\"%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS\", now);\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ P_2_1_3_02.pde \/\/ \/\/ Generative Gestaltung, ISBN: 978-3-87439-759-9 \/\/ First Edition, Hermann Schmidt, Mainz, 2009 \/\/ Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni \/\/ Copyright 2009 Hartmut Bohnacker, Benedikt Gross, Julia Laub, Claudius Lazzeroni \/\/ \/\/ http:\/\/www.generative-gestaltung.de \/** * draw a module made of lines in a grid * * MOUSE * position x [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-241","post","type-post","status-publish","format-standard","hentry","category-lessons"],"_links":{"self":[{"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/posts\/241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/comments?post=241"}],"version-history":[{"count":1,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/posts\/241\/revisions"}],"predecessor-version":[{"id":242,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/posts\/241\/revisions\/242"}],"wp:attachment":[{"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/media?parent=241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/categories?post=241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/tags?post=241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}