{"id":2597,"date":"2016-02-13T23:06:47","date_gmt":"2016-02-13T22:06:47","guid":{"rendered":"http:\/\/www.lyceelecorbusier.eu\/p5js\/?p=2597"},"modified":"2016-09-09T17:00:43","modified_gmt":"2016-09-09T16:00:43","slug":"p5-js-p_2_2_4_01","status":"publish","type":"post","link":"https:\/\/www.lyceelecorbusier.eu\/p5js\/?p=2597","title":{"rendered":"\/ p5.js \/ P_2_2_4_01"},"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_01\" 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_01\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* s\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\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 circles\r\nvar currentCount = 1;\r\nvar x = [maxCount];\r\nvar y = [maxCount];\r\nvar r = [maxCount];\r\n\r\nfunction setup() {\r\n\u00a0 createCanvas(780,780);\r\n\u00a0 smooth();\r\n\u00a0 \/\/frameRate(10);\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] = 400; \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 radom 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\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\r\n\u00a0 \/\/ show random position and line\r\n\u00a0 \/\/ fill(230);\r\n\u00a0 \/\/ ellipse(newX,newY,newR*2,newR*2); \r\n\u00a0 \/\/ line(newX,newY,x[closestIndex],y[closestIndex]);\r\n\r\n\u00a0 \/\/ aline it to the closest circle outline\r\n\u00a0 var angle = atan2(newY-y[closestIndex], newX-x[closestIndex]);\r\n\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 them\r\n\u00a0 for (var i=0 ; i &lt; currentCount; i++) {\r\n\u00a0\u00a0\u00a0 fill(236,36,95);\r\n\u00a0\u00a0\u00a0 noStroke();\r\n\u00a0\u00a0 \/\/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 keyPressed() {\r\n\u00a0 if (key == 's' || key == 'S') save(\"P_2_2_4_01.png\");\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":2598,"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\/2597"}],"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=2597"}],"version-history":[{"count":1,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/posts\/2597\/revisions"}],"predecessor-version":[{"id":2599,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/posts\/2597\/revisions\/2599"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/media\/2598"}],"wp:attachment":[{"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}