{"id":2583,"date":"2016-02-13T15:48:43","date_gmt":"2016-02-13T14:48:43","guid":{"rendered":"http:\/\/www.lyceelecorbusier.eu\/p5js\/?p=2583"},"modified":"2016-09-09T17:00:43","modified_gmt":"2016-09-09T16:00:43","slug":"p5-js-p_2_2_1_02","status":"publish","type":"post","link":"https:\/\/www.lyceelecorbusier.eu\/p5js\/?p=2583","title":{"rendered":"\/ p5.js \/ P_2_2_1_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_1_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_1_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\/**\r\n\u00a0* draw the path of a stupid agent\r\n\u00a0*\r\n\u00a0* MOUSE\r\n\u00a0* position x\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : drawing speed\r\n\u00a0*\r\n\u00a0* KEYS\r\n\u00a0* 1-3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : draw mode of the agent\r\n\u00a0* BACKSPACE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : clear display\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\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : start pdf recording\r\n\u00a0* e\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : stop pdf recording\r\n\u00a0*\/\r\n\r\n\r\nvar NORTH = 0;\r\nvar NORTHEAST = 1; \r\nvar EAST = 2;\r\nvar SOUTHEAST = 3;\r\nvar SOUTH = 4;\r\nvar SOUTHWEST = 5;\r\nvar WEST = 6;\r\nvar NORTHWEST= 7;\r\n\r\nvar stepSize = 1;\r\nvar diameter = 1;\r\n\r\nvar drawMode = 1;\r\nvar counter = 0;\r\n\r\nvar direction;\r\nvar posX, posY;\r\n\r\n\r\nfunction setup() {\r\n\u00a0 createCanvas(780, 780);\r\n\u00a0 colorMode(HSB, 360, 100, 100, 100);\r\n\u00a0 background(360);\r\n\u00a0 smooth();\r\n\u00a0 noStroke();\r\n\r\n\u00a0 posX = width\/2;\r\n\u00a0 posY = height\/2;\r\n}\r\n\r\n\r\nfunction draw() {\r\n\u00a0\u00a0\u00a0 colorMode(HSB, 360, 100, 100, 100);\r\n\u00a0 for (var i=0; i&lt;=mouseX; i++) {\r\n\u00a0\u00a0\u00a0 counter++;\r\n\r\n\u00a0\u00a0\u00a0 \/\/ random number for the direction of the next step\r\n\u00a0\u00a0\u00a0 if (drawMode == 2) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 direction = round(random(0, 3));\u00a0\u00a0\u00a0 \/\/ only NORTH, NORTHEAST, EAST possible\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 else {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 direction = int(random(0, 7));\u00a0\u00a0\u00a0 \/\/ all directions without NORTHWEST\r\n\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0\u00a0 if (direction == NORTH) { \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 posY -= stepSize; \u00a0\r\n\u00a0\u00a0\u00a0 } \r\n\u00a0\u00a0\u00a0 else if (direction == NORTHEAST) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 posX += stepSize;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 posY -= stepSize;\r\n\u00a0\u00a0\u00a0 } \r\n\u00a0\u00a0\u00a0 else if (direction == EAST) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 posX += stepSize;\r\n\u00a0\u00a0\u00a0 } \r\n\u00a0\u00a0\u00a0 else if (direction == SOUTHEAST) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 posX += stepSize;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 posY += stepSize;\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 else if (direction == SOUTH) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 posY += stepSize;\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 else if (direction == SOUTHWEST) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 posX -= stepSize;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 posY += stepSize;\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 else if (direction == WEST) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 posX -= stepSize;\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 else if (direction == NORTHWEST) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 posX -= stepSize;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 posY -= stepSize;\r\n\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0\u00a0 if (posX &gt; width) posX = 0;\r\n\u00a0\u00a0\u00a0 if (posX &lt; 0) posX = width;\r\n\u00a0\u00a0\u00a0 if (posY &lt; 0) posY = height;\r\n\u00a0\u00a0\u00a0 if (posY &gt; height) posY = 0;\r\n\u00a0\u00a0\u00a0 if (drawMode == 3) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 if (counter &gt;= 100){\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 counter = 0;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fill(192, 100, 64, 80);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ellipse(posX+stepSize\/2, posY+stepSize\/2, diameter+7, diameter+7);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 } \r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 fill(0, 40);\r\n\u00a0\u00a0\u00a0 ellipse(posX+stepSize\/2, posY+stepSize\/2, diameter, diameter);\r\n\u00a0 }\r\n}\r\n\r\n\r\nfunction keyPressed(){\r\n\u00a0 if (keyCode == DELETE || keyCode == BACKSPACE) background(360);\r\n} \u00a0\r\nfunction keyTyped(){\r\n\u00a0 if (key == 's' || key == 'S') save(\"P_2_2_1_02.png\");\r\n\r\n\u00a0 if (key == '1') {\r\n\u00a0\u00a0\u00a0 drawMode = 1;\r\n\u00a0\u00a0\u00a0 stepSize = 1;\r\n\u00a0\u00a0\u00a0 diameter = 1;\r\n\u00a0 }\r\n\u00a0 if (key == '2') {\r\n\u00a0\u00a0\u00a0 drawMode = 2;\r\n\u00a0\u00a0\u00a0 stepSize = 1;\r\n\u00a0\u00a0\u00a0 diameter = 1;\r\n\u00a0 }\r\n\u00a0 if (key == '3') {\r\n\u00a0\u00a0\u00a0 drawMode = 3;\r\n\u00a0\u00a0\u00a0 stepSize = 10;\r\n\u00a0\u00a0\u00a0 diameter = 5;\r\n\u00a0 }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":2584,"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\/2583"}],"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=2583"}],"version-history":[{"count":1,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/posts\/2583\/revisions"}],"predecessor-version":[{"id":2585,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/posts\/2583\/revisions\/2585"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/media\/2584"}],"wp:attachment":[{"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}