{"id":32,"date":"2011-02-12T16:07:51","date_gmt":"2011-02-12T16:07:51","guid":{"rendered":"http:\/\/classes.visitsteve.com\/hacking\/?p=32"},"modified":"2011-02-12T16:07:51","modified_gmt":"2011-02-12T16:07:51","slug":"bouncing-ball","status":"publish","type":"post","link":"https:\/\/classes.visitsteve.com\/hacking\/bouncing-ball\/","title":{"rendered":"bouncing ball"},"content":{"rendered":"<p>click to drop again.<br \/>\n<script type=\"application\/processing\">\r\n\/\/Info: http:\/\/processingjs.org\/reference\r\nboolean button = false; \/\/ initial state for start\/stop switch\r\n\r\n\/\/ setting up variables\r\nfloat locX = 0; \/\/ location X\r\nfloat locY = 100; \/\/ location Y\r\nfloat xSpeed = random(1,3); \/\/ Speed on X axis\r\nfloat ySpeed = random(1,3); \/\/ Speed on Y axis\r\nfloat gravity = 0.1; \/\/ gravity!\r\n\r\nvoid setup() { \r\n  size(200,200);\r\n  ellipseMode(CORNER);\r\n}\r\n\r\nvoid draw() { \r\n  background(255);\r\n  stroke(255);\r\n  fill(255,166,70); \/\/ orange!\r\n  \r\n  locX = locX + xSpeed; \/\/ x = x + 1 ... but with variables\r\n  locY = locY + ySpeed; \/\/ y = y + 1 ... but with variables\r\n  \r\n  ySpeed = ySpeed + gravity; \/\/ speed on y axis is affected by gravity, always pushing down \r\n  \r\n  \/\/ if object gets to the edge, go the other way.\r\n  if ((locX > width-21) || (locX < 1)){\r\n   xSpeed = xSpeed * -1;\r\n  } \r\n  \r\n  if ((locY > height-21) || (locY < 1)){\r\n   ySpeed = ySpeed * -.75; \/\/ inertia?\r\n  } \r\n    \r\n  \/\/draw the circle  \r\n  ellipse(locX,locY,20,20);\r\n  \r\n  \/\/ Increment x \r\n  if (button) {\r\n  locX = locX + xSpeed;\r\n  locY = locY + ySpeed;\r\n  } else {\r\n  locX = locX;\r\n  locY = locY;\r\n  }\r\n\r\n  \r\n  locX = constrain(locX,0,width-20);\r\n  locY = constrain(locY,0,height-20);\r\n}\r\n\r\nvoid mousePressed() {\r\n    locX = mouseX;\r\n    locY = mouseY;\r\n    xSpeed = int(random(-3,3));\r\n    ySpeed = int(random(-3,3));\r\n    \r\n}\r\n\r\nvoid keyPressed() {\r\n  button = !button; \r\n}\r\n<\/script><\/p>\n<h2>code<\/h2>\n<p><code><br \/>\nboolean button = false; \/\/ initial state for start\/stop switch<\/p>\n<p>\/\/ setting up variables<br \/>\nfloat locX = 0; \/\/ location X<br \/>\nfloat locY = 100; \/\/ location Y<br \/>\nfloat xSpeed = random(1,3); \/\/ Speed on X axis<br \/>\nfloat ySpeed = random(1,3); \/\/ Speed on Y axis<br \/>\nfloat gravity = 0.1; \/\/ gravity!<\/p>\n<p>void setup() {<br \/>\n  size(200,200);<br \/>\n  ellipseMode(CORNER);<br \/>\n}<\/p>\n<p>void draw() {<br \/>\n  background(255);<br \/>\n  stroke(255);<br \/>\n  fill(255,166,70); \/\/ orange!<\/p>\n<p>  locX = locX + xSpeed; \/\/ x = x + 1 ... but with variables<br \/>\n  locY = locY + ySpeed; \/\/ y = y + 1 ... but with variables<\/p>\n<p>  ySpeed = ySpeed + gravity; \/\/ speed on y axis is affected by gravity, always pushing down <\/p>\n<p>  \/\/ if object gets to the edge, go the other way.<br \/>\n  if ((locX > width-21) || (locX < 1)){\n   xSpeed = xSpeed * -1;\n  } \n  \n  if ((locY > height-21) || (locY < 1)){\n   ySpeed = ySpeed * -.75; \/\/ inertia?\n  } \n    \n  \/\/draw the circle  \n  ellipse(locX,locY,20,20);\n  \n  \/\/ Increment x \n  if (button) {\n  locX = locX + xSpeed;\n  locY = locY + ySpeed;\n  } else {\n  locX = locX;\n  locY = locY;\n  }\n\n  \n  locX = constrain(locX,0,width-20);\n  locY = constrain(locY,0,height-20);\n}\n\nvoid mousePressed() {\n    locX = mouseX;\n    locY = mouseY;\n    xSpeed = int(random(-3,3));\n    ySpeed = int(random(-3,3));\n    \n}\n\nvoid keyPressed() {\n  button = !button; \n}\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>click to drop again. code boolean button = false; \/\/ initial state for start\/stop switch \/\/ setting up variables float locX = 0; \/\/ location X float locY = 100; \/\/ location Y float xSpeed = random(1,3); \/\/ Speed on &hellip; <a href=\"https:\/\/classes.visitsteve.com\/hacking\/bouncing-ball\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-32","post","type-post","status-publish","format-standard","hentry","category-classnews"],"_links":{"self":[{"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/posts\/32","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/comments?post=32"}],"version-history":[{"count":0,"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/posts\/32\/revisions"}],"wp:attachment":[{"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/media?parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/categories?post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/tags?post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}