{"id":2649,"date":"2016-02-28T19:14:14","date_gmt":"2016-02-28T18:14:14","guid":{"rendered":"http:\/\/www.lyceelecorbusier.eu\/p5js\/?p=2649"},"modified":"2016-09-09T17:00:43","modified_gmt":"2016-09-09T16:00:43","slug":"p5-js-p_2_3_1_02","status":"publish","type":"post","link":"https:\/\/www.lyceelecorbusier.eu\/p5js\/?p=2649","title":{"rendered":"\/ p5.js \/ P_2_3_2_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_2_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_2_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 work with relations between 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\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 : line length +\r\n\u00a0* arrow down\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : line length -\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\nvar drawMode = 1;\r\n\r\nvar col = 0;\r\nvar x = 0, y = 0;\r\n\/\/float newX = 0, newY = 0;\r\nvar stepSize = 5.0;\r\nvar lineLength = 25;\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 x = mouseX;\r\n\u00a0 y = mouseY;\r\n\u00a0 cursor(CROSS);\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\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);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 stroke(col);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 if (frameCount % 2 == 0) stroke(150);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 line(0,0,0,lineLength*random(0.95,1.0)*d\/10);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 pop();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 x = x + cos(angle) * stepSize;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 y = y + sin(angle) * stepSize; \r\n\u00a0\u00a0\u00a0\u00a0\u00a0 } \r\n\u00a0\u00a0\u00a0\u00a0\u00a0 else {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 x\u00a0 = mouseX;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 y\u00a0 = mouseY; \r\n\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\u00a0 col = color(random(255),random(255),random(255),random(100));\r\n\u00a0}\r\n\r\nfunction keyTyped() {\r\n\u00a0 if (key == 's' || key == 'S') save(\"P_2_3_2_01.png\");\r\n}\r\n\r\nfunction keyPressed() {\r\n\u00a0 if (keyCode == DELETE || key == BACKSPACE) background(255);\r\n\u00a0 \/\/ lineLength ctrls arrowkeys up\/down \r\n\u00a0 if (keyCode == UP_ARROW) lineLength += 5;\r\n\u00a0 if (keyCode == DOWN_ARROW) lineLength -= 5; \r\n}<\/pre>\n<p style=\"text-align: left;\">\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":2650,"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\/2649"}],"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=2649"}],"version-history":[{"count":2,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/posts\/2649\/revisions"}],"predecessor-version":[{"id":2652,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/posts\/2649\/revisions\/2652"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=\/wp\/v2\/media\/2650"}],"wp:attachment":[{"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lyceelecorbusier.eu\/p5js\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}