{"id":252,"date":"2015-06-22T15:15:43","date_gmt":"2015-06-22T11:15:43","guid":{"rendered":"http:\/\/courses.haigarmen.com\/creativecoding\/?p=252"},"modified":"2015-06-23T09:08:44","modified_gmt":"2015-06-23T05:08:44","slug":"exercise-53","status":"publish","type":"post","link":"https:\/\/courses.haigarmen.com\/creativecoding\/exercise-53\/","title":{"rendered":"Exercise 53"},"content":{"rendered":"<pre><code>\r\n\/\/ P_2_1_3_04.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 * changing positions of stapled circles in a grid\r\n * \t \r\n * MOUSE\r\n * position x          : module detail\r\n * position y          : module parameter\r\n * \r\n * KEYS\r\n * 1-3                 : draw mode\r\n * arrow left\/right    : number of tiles horizontally\r\n * arrow up\/down       : number of tiles vertically\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 = 6;\r\nfloat tileCountY = 6;\r\nint count = 0;\r\n\r\nint drawMode = 1;\r\n\r\n\r\nvoid setup() { \r\n  size(550, 550);\r\n} \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  rectMode(CENTER);\r\n  smooth();\r\n  stroke(0);\r\n  noFill();\r\n  background(360); \r\n  \r\n  count = mouseX\/10 + 10;\r\n  float para = (float)mouseY\/height;\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 + tileWidth\/2;\r\n      float posY = tileHeight*gridY + tileHeight\/2;\r\n\r\n      pushMatrix();\r\n      translate(posX, posY);\r\n\r\n      \/\/ switch between modules\r\n      switch (drawMode) {\r\n      case 1:\r\n        for(int i=0; i < count; i++) {\r\n          rect(0, 0, tileWidth, tileHeight);\r\n          scale(1 - 3.0\/count);\r\n          rotate(para*0.1);\r\n        }\r\n        break;\r\n\r\n      case 2:\r\n        for(float i=0; i < count; i++) {\r\n          noStroke();\r\n          color gradient = lerpColor(color(0), color(52, 100, 71), i\/count);\r\n          fill(gradient, i\/count*200);\r\n          rotate(PI\/4);\r\n          rect(0, 0, tileWidth, tileHeight);\r\n          scale(1 - 3.0\/count);\r\n          rotate(para*1.5);\r\n        }\r\n        break;\r\n\r\n      case 3:\r\n        colorMode(RGB, 255);\r\n        for(float i=0; i < count; i++) {\r\n          noStroke();\r\n          color gradient = lerpColor(color(0, 130, 164), color(255), i\/count);\r\n          fill(gradient,170);\r\n\r\n          pushMatrix();\r\n          translate(4*i,0);\r\n          ellipse(0, 0, tileWidth\/4, tileHeight\/4);\r\n          popMatrix();\r\n\r\n          pushMatrix();\r\n          translate(-4*i,0);\r\n          ellipse(0, 0, tileWidth\/4, tileHeight\/4);\r\n          popMatrix();\r\n\r\n          scale(1 - 1.5\/count);\r\n          rotate(para*1.5);\r\n        }\r\n\r\n        break;\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 keyReleased(){\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  if (keyCode == DOWN) tileCountY = max(tileCountY-1, 1);\r\n  if (keyCode == UP) tileCountY += 1;\r\n  if (keyCode == LEFT) tileCountX = max(tileCountX-1, 1);\r\n  if (keyCode == RIGHT) tileCountX += 1;\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_04.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 \/** * changing positions of stapled circles 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-252","post","type-post","status-publish","format-standard","hentry","category-lessons"],"_links":{"self":[{"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/posts\/252","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=252"}],"version-history":[{"count":1,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/posts\/252\/revisions"}],"predecessor-version":[{"id":253,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/posts\/252\/revisions\/253"}],"wp:attachment":[{"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/media?parent=252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/categories?post=252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/tags?post=252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}