{"id":230,"date":"2015-06-22T13:56:18","date_gmt":"2015-06-22T09:56:18","guid":{"rendered":"http:\/\/courses.haigarmen.com\/creativecoding\/?p=230"},"modified":"2015-06-22T16:24:23","modified_gmt":"2015-06-22T12:24:23","slug":"exercise-51","status":"publish","type":"post","link":"https:\/\/courses.haigarmen.com\/creativecoding\/exercise-51\/","title":{"rendered":"Exercise 51"},"content":{"rendered":"<pre><code>\r\n\/\/ P_2_1_3_01.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\/**\r\n * changing circle amount, size and position in a grid\r\n * \t \r\n * MOUSE\r\n * position x          : circle amount and size\r\n * position y          : circle position\r\n * left click          : random position\r\n * \r\n * KEYS\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\nfloat tileCountX = 10;\r\nfloat tileCountY = 10;\r\nfloat tileWidth, tileHeight;\r\n\r\nint count = 0;\r\nint colorStep = 15;\r\nint circleCount;\r\nfloat endSize, endOffset;\r\n\r\nint actRandomSeed = 0;\r\n\r\n\r\nvoid setup() { \r\n  size(800, 800);\r\n  tileWidth = width \/ tileCountX;\r\n  tileHeight = height \/ tileCountY;\r\n} \r\n\r\n\r\nvoid draw() { \r\n  if (savePDF) beginRecord(PDF, timestamp()+\".pdf\");\r\n\r\n  smooth();\r\n  noFill();\r\n  stroke(0, 128);\r\n  background(255); \r\n  randomSeed(actRandomSeed);\r\n\r\n  translate((width\/tileCountX)\/2, (height\/tileCountY)\/2);\r\n\r\n  circleCount = mouseX\/30 + 1;\r\n  endSize = map(mouseX, 0, width, tileWidth\/2.0, 0);\r\n  endOffset = map(mouseY, 0, height, 0, (tileWidth-endSize)\/2);\r\n\r\n  for (int gridY=0; gridY <= tileCountY; gridY++) {\r\n    for (int gridX=0; gridX <= tileCountX; gridX++) {  \r\n      pushMatrix();\r\n      translate(tileWidth*gridX, tileHeight*gridY);\r\n      scale(1, tileHeight\/tileWidth);\r\n\r\n      int toggle = (int) random(0, 4);\r\n      if (toggle == 0) rotate(-HALF_PI);  \r\n      if (toggle == 1) rotate(0);  \r\n      if (toggle == 2) rotate(HALF_PI);  \r\n      if (toggle == 3) rotate(PI);  \r\n\r\n      \/\/ draw module\r\n      for (int i=0; i < circleCount; i++) {\r\n        float diameter = map(i, 0, circleCount-1, tileWidth, endSize);\r\n        float offset = map(i, 0, circleCount-1, 0, endOffset);\r\n        ellipse(offset, 0, diameter, diameter);\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 mousePressed() {\r\n  actRandomSeed = (int) random(100000);\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\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_01.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 circle amount, size and position 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-230","post","type-post","status-publish","format-standard","hentry","category-lessons"],"_links":{"self":[{"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/posts\/230","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=230"}],"version-history":[{"count":4,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/posts\/230\/revisions"}],"predecessor-version":[{"id":245,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/posts\/230\/revisions\/245"}],"wp:attachment":[{"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/media?parent=230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/categories?post=230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.haigarmen.com\/creativecoding\/wp-json\/wp\/v2\/tags?post=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}