{"id":2653,"date":"2016-02-28T19:20:41","date_gmt":"2016-02-28T18:20:41","guid":{"rendered":"http:\/\/www.lyceelecorbusier.eu\/p5js\/?p=2653"},"modified":"2016-09-09T17:00:42","modified_gmt":"2016-09-09T16:00:42","slug":"p5-js-p_2_3_3_01","status":"publish","type":"post","link":"https:\/\/www.lyceelecorbusier.eu\/p5js\/?p=2653","title":{"rendered":"\/ p5.js \/ P_2_3_3_01"},"content":{"rendered":"<p style=\"text-align: center;\"><!--more--><\/p>\n<p style=\"text-align: center;\">\n<!-- iframe plugin v.5.1 wordpress.org\/plugins\/iframe\/ -->\n<iframe src=\"http:\/\/lyceelecorbusier.eu\/p5\/generative\/P_2_3_3_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_3_3_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\/**\r\n\u00a0* draw tool. shows how to draw with dynamic elements. \r\n\u00a0* \r\n\u00a0* MOUSE\r\n\u00a0* drag\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : draw with text\r\n\u00a0* \r\n\u00a0* KEYS\r\n\u00a0* del, backspace\u00a0\u00a0\u00a0\u00a0\u00a0 : clear screen\r\n\u00a0* arrow up\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : angle distortion +\r\n\u00a0* arrow down\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : angle distortion -\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\r\n\u00a0*\/\r\n\r\nvar x = 0, y = 0;\r\nvar stepSize = 5.0;\r\nvar letters = \"Mon propos dans les pages qui suivent a plut\u00f4t \u00e9t\u00e9 de d\u00e9crire le reste : ce que l'on ne note g\u00e9n\u00e9ralement pas, ce qui ne se remarque pas, ce qui n'a pas d'importance : ce qui se passe quand il ne se passe rien, sinon du temps, des gens, des voitures et des nuages.\";\r\nvar fontSizeMin = 3;\r\nvar angleDistortion = 0.0;\r\nvar counter = 0;\r\n\r\n\r\nfunction setup() {\r\n\u00a0 \/\/ use full screen size \r\n\u00a0 createCanvas(780, 780);\r\n\u00a0 background(255);\r\n\u00a0 smooth();\r\n\u00a0 cursor(CROSS);\r\n\u00a0\r\n\u00a0 x = mouseX;\r\n\u00a0 y = mouseY;\r\n\r\n\u00a0 textAlign(LEFT);\r\n\u00a0 fill(0);\r\n\r\n}\r\n\r\nfunction draw() {\r\n\u00a0 if (mouseIsPressed) {\r\n\u00a0\u00a0\u00a0 var d = dist(x,y, mouseX,mouseY);\r\n\u00a0\u00a0\u00a0 textFont('Georgia');\r\n\u00a0\u00a0\u00a0 textSize(fontSizeMin+d\/2)\r\n\u00a0\u00a0\u00a0 var newLetter = letters.charAt(counter);;\r\n\u00a0\u00a0\u00a0 stepSize = textWidth(newLetter);\r\n\r\n\u00a0\u00a0\u00a0 if (d &gt; stepSize) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 var angle = atan2(mouseY-y, mouseX-x); \r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 push();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 translate(x, y);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 rotate(angle + random(angleDistortion));\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 text(newLetter, 0, 0);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 pop();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 counter++;\r\n\u00a0\u00a0\u00a0\u00a0 if (counter &gt; letters.length-1) counter = 0;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 x = x + cos(angle) * stepSize;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 y = y + sin(angle) * stepSize; \r\n\u00a0\u00a0\u00a0 }\r\n\u00a0 }\r\n}\r\n\r\nfunction mousePressed() {\r\n\u00a0 x = mouseX;\r\n\u00a0 y = mouseY;\r\n}\r\n\r\nfunction keyTyped() {\r\n\u00a0 if (key == 's' || key == 'S') save(\"P_2_3_3_01.png\");\r\n}\r\n\r\nfunction keyPressed() {\r\n\u00a0 \/\/ angleDistortion ctrls arrowkeys up\/down \r\n\u00a0 if (keyCode == DELETE || keyCode == BACKSPACE) background(255);\r\n\u00a0 if (keyCode == UP_ARROW) angleDistortion += 0.1;\r\n\u00a0 if (keyCode == DOWN_ARROW) angleDistortion -= 0.1; \r\n}<\/pre>\n<p style=\"text-align: left;\">\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":2654,"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\/2653"}],"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=2653"}],"version-history":[{"count":4,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/posts\/2653\/revisions"}],"predecessor-version":[{"id":2658,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/posts\/2653\/revisions\/2658"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/media\/2654"}],"wp:attachment":[{"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}