{"id":236,"date":"2015-06-22T15:14:13","date_gmt":"2015-06-22T11:14:13","guid":{"rendered":"http:\/\/courses.haigarmen.com\/creativecoding\/?p=236"},"modified":"2015-06-22T16:35:13","modified_gmt":"2015-06-22T12:35:13","slug":"exercise-52","status":"publish","type":"post","link":"https:\/\/courses.haigarmen.com\/creativecoding\/exercise-52\/","title":{"rendered":"Exercise 52"},"content":{"rendered":"<pre><code>\r\n\/\/ P_2_1_2_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 * changing module color and positions in a grid\r\n * \t \r\n * MOUSE\r\n * position x          : offset x\r\n * position y          : offset y\r\n * left click          : random position\r\n * \r\n * KEYS\r\n * 1-3                 : different sets of colors\r\n * 0                   : default\r\n * arrow up\/down       : background module size\r\n * arrow left\/right    : foreground module size\r\n * s                   : save png\r\n * p                   : save pdf\r\n *\/\r\n\r\nimport processing.pdf.*;\r\nimport java.util.Calendar;\r\n\r\nboolean savePDF = false;\r\n\r\ncolor moduleColorBackground = color(0);\r\ncolor moduleColorForeground = color(255);\r\n\r\ncolor moduleAlphaBackground = 100;\r\ncolor moduleAlphaForeground = 100;\r\n\r\nfloat moduleRadiusBackground = 30;\r\nfloat moduleRadiusForeground = 15;\r\n\r\ncolor backColor = color(255);\r\n\r\n\r\nfloat tileCount = 20;\r\nint actRandomSeed = 0;\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  translate(width\/tileCount\/2, height\/tileCount\/2);\r\n\r\n  colorMode(HSB, 360, 100, 100, 100);\r\n  background(backColor);\r\n  smooth();\r\n  noStroke();\r\n\r\n  randomSeed(actRandomSeed);\r\n\r\n  for (int gridY=0; gridY < tileCount; gridY++) {\r\n    for (int gridX=0; gridX < tileCount; gridX++) {\r\n      float posX = width\/tileCount * gridX;\r\n      float posY = height\/tileCount * gridY;\r\n\r\n      float shiftX =  random(-1, 1) * mouseX\/20;\r\n      float shiftY =  random(-1, 1) * mouseY\/20;\r\n\r\n      fill(moduleColorBackground, moduleAlphaBackground);\r\n      ellipse(posX+shiftX, posY+shiftY, moduleRadiusBackground, moduleRadiusBackground);\r\n    }\r\n  }\r\n\r\n  for (int gridY=0; gridY < tileCount; gridY++) {\r\n    for (int gridX=0; gridX < tileCount; gridX++) {\r\n\r\n      float posX = width\/tileCount * gridX;\r\n      float posY = height\/tileCount * gridY;\r\n\r\n      fill(moduleColorForeground, moduleAlphaForeground);\r\n      ellipse(posX, posY, moduleRadiusForeground, moduleRadiusForeground);\r\n    }\r\n  }\r\n\r\n  if (savePDF) {\r\n    savePDF = false;\r\n    endRecord();\r\n  }\r\n}\r\n\r\nvoid mousePressed() {\r\n  actRandomSeed = (int) random(100000);\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'){\r\n    if (moduleColorBackground == color(0)) {\r\n      moduleColorBackground = color(273, 73, 51);\r\n    } \r\n    else {\r\n      moduleColorBackground = color(0);\r\n    } \r\n  }\r\n  if (key == '2'){\r\n    if (moduleColorForeground == color(360)) {\r\n      moduleColorForeground = color(323, 100, 77);\r\n    } \r\n    else {\r\n      moduleColorForeground = color(360);\r\n    } \r\n  }\r\n\r\n  if (key == '3'){\r\n    if (moduleAlphaBackground == 100) {\r\n      moduleAlphaBackground = 50;\r\n      moduleAlphaForeground = 50;\r\n    } \r\n    else {\r\n      moduleAlphaBackground = 100;\r\n      moduleAlphaForeground = 100;\r\n    } \r\n  }\r\n\r\n\r\n  if (key == '0'){  \r\n    moduleColorBackground = color(0);\r\n    moduleColorForeground = color(360);\r\n    moduleAlphaBackground = 100;\r\n    moduleAlphaForeground = 100;\r\n    moduleRadiusBackground = 20;\r\n    moduleRadiusForeground = 10;\r\n  }\r\n\r\n  if (keyCode == UP) moduleRadiusBackground += 2;\r\n  if (keyCode == DOWN) moduleRadiusBackground = max(moduleRadiusBackground-2, 10);\r\n  if (keyCode == LEFT) moduleRadiusForeground = max(moduleRadiusForeground-2, 5);\r\n  if (keyCode == RIGHT) moduleRadiusForeground += 2;\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_2_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 \/** * changing module color and positions 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-236","post","type-post","status-publish","format-standard","hentry","category-lessons"],"_links":{"self":[{"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/posts\/236","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=236"}],"version-history":[{"count":2,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/posts\/236\/revisions"}],"predecessor-version":[{"id":246,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/posts\/236\/revisions\/246"}],"wp:attachment":[{"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/media?parent=236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/categories?post=236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/tags?post=236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}