{"id":2603,"date":"2016-02-13T23:29:20","date_gmt":"2016-02-13T22:29:20","guid":{"rendered":"http:\/\/www.lyceelecorbusier.eu\/p5js\/?p=2603"},"modified":"2016-09-09T17:00:43","modified_gmt":"2016-09-09T16:00:43","slug":"p5-js-p_2_2_4_02","status":"publish","type":"post","link":"https:\/\/www.lyceelecorbusier.eu\/p5js\/?p=2603","title":{"rendered":"\/ p5.js \/ P_2_2_4_02"},"content":{"rendered":"<p style=\"text-align: center;\"><!--more-->\n<!-- iframe plugin v.5.1 wordpress.org\/plugins\/iframe\/ -->\n<iframe src=\"http:\/\/lyceelecorbusier.eu\/p5\/generative\/P_2_2_4_02\" width=\"780\" height=\"780\" style=\"border: 1px solid #ddd;\" scrolling=\"yes\" class=\"iframe-class\" frameborder=\"0\"><\/iframe>\n\n<pre style=\"text-align: left;\">\/\/ P_2_2_4_02\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\/\/ Licensed under the Apache License, Version 2.0 (the \"License\");\r\n\/\/ you may not use this file except in compliance with the License.\r\n\/\/ You may obtain a copy of the License at http:\/\/www.apache.org\/licenses\/LICENSE-2.0\r\n\/\/ Unless required by applicable law or agreed to in writing, software\r\n\/\/ distributed under the License is distributed on an \"AS IS\" BASIS,\r\n\/\/ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n\/\/ See the License for the specific language governing permissions and\r\n\/\/ limitations under the License.\r\n\/**\r\n\u00a0* limited diffusion aggregation \r\n\u00a0* \r\n\u00a0* KEYS\r\n\u00a0* 1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : toggle draw original position of circles\r\n\u00a0* s\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : save png\r\n\u00a0*\/\r\n\r\nvar maxCount = 5000; \/\/max count of the cirlces\r\nvar currentCount = 1;\r\nvar newx = [maxCount];\r\nvar newy = [maxCount];\r\nvar x = [maxCount];\r\nvar y = [maxCount];\r\nvar r = [maxCount]; \/\/ radius\r\nvar drawGhosts = false;\r\n\r\nfunction setup() {\r\n\u00a0 createCanvas(780, 780);\r\n\u00a0 smooth();\r\n\u00a0 \/\/ first circle\r\n\u00a0 x[0] = width\/2;\r\n\u00a0 y[0] = height\/2;\r\n\u00a0 \/\/r[0] = 10;\r\n\u00a0 r[0] = 360; \r\n}\r\n\r\nfunction draw() {\r\n\u00a0 background(255);\r\n\u00a0 strokeWeight(0.5);\r\n\u00a0 \/\/noFill();\r\n\r\n\u00a0 \/\/ create a random set of parameters\r\n\u00a0 var newR = random(1, 7);\r\n\u00a0 var newX = random(0+newR, width-newR);\r\n\u00a0 var newY = random(0+newR, height-newR);\r\n\u00a0 var closestDist = 100000000;\r\n\u00a0 var closestIndex = 0;\r\n\u00a0 \/\/ which circle is the closest?\r\n\u00a0 for(var i=0; i &lt; currentCount; i++) {\r\n\u00a0\u00a0\u00a0 var newDist = dist(newX,newY, x[i],y[i]);\r\n\u00a0\u00a0\u00a0 if (newDist &lt; closestDist) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 closestDist = newDist;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 closestIndex = i; \r\n\u00a0\u00a0\u00a0 } \r\n\u00a0 }\r\n\u00a0 \/\/ aline it to the closest circle outline\r\n\u00a0 var angle = atan2(newY-y[closestIndex], newX-x[closestIndex]);\r\n\u00a0 newx[currentCount] = newX;\r\n\u00a0 newy[currentCount] = newY;\r\n\u00a0 x[currentCount] = x[closestIndex] + cos(angle) * (r[closestIndex]+newR);\r\n\u00a0 y[currentCount] = y[closestIndex] + sin(angle) * (r[closestIndex]+newR);\r\n\u00a0 r[currentCount] = newR;\r\n\u00a0 currentCount++;\r\n\r\n\u00a0 \/\/ draw circles at random position and lines\r\n\u00a0 if (drawGhosts) {\r\n\u00a0\u00a0\u00a0 for (var i=1 ; i &lt; currentCount; i++) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 fill(230);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 ellipse(newx[i],newy[i], r[i]*2,r[i]*2); \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 line(newx[i],newy[i], x[i],y[i]);\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0 }\r\n\r\n\u00a0 for (var i=0 ; i &lt; currentCount; i++) {\r\n\u00a0\u00a0\u00a0 if (i == 0) noFill();\r\n\u00a0\u00a0\u00a0 else fill(50);\r\n\u00a0\u00a0\u00a0 ellipse(x[i],y[i], r[i]*2,r[i]*2); \u00a0\r\n\u00a0 }\r\n\u00a0 if (currentCount &gt;= maxCount) noLoop();\r\n}\r\n\r\nfunction keyTyped() {\r\n\u00a0 if (key == 's' || key == 'S') save(\"P_2_2_4_02.png\");\r\n\u00a0 if (key == '1') drawGhosts = !drawGhosts;\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":2604,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[10,6],"tags":[],"_links":{"self":[{"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/posts\/2603"}],"collection":[{"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2603"}],"version-history":[{"count":1,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/posts\/2603\/revisions"}],"predecessor-version":[{"id":2605,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/posts\/2603\/revisions\/2605"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/media\/2604"}],"wp:attachment":[{"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}