{"id":29,"date":"2011-02-12T04:34:32","date_gmt":"2011-02-12T04:34:32","guid":{"rendered":"http:\/\/classes.visitsteve.com\/hacking\/?p=29"},"modified":"2011-02-12T04:34:32","modified_gmt":"2011-02-12T04:34:32","slug":"dimmer-switch","status":"publish","type":"post","link":"https:\/\/classes.visitsteve.com\/hacking\/dimmer-switch\/","title":{"rendered":"Dimmer Switch"},"content":{"rendered":"<p><script type=\"application\/processing\">\r\n\/\/Info: http:\/\/processingjs.org\/reference\r\n\/\/ Dimmer Switch\r\n\/\/ 2\/10\/11\r\n\r\nboolean button = false;\r\n\r\nint x = 50; \r\nint y = 50; \r\nint w = 100; \r\nint h = 75;\r\nfloat change = 5; \/\/ fade rate\r\nfloat gs; \/\/greyscale\r\n\r\nvoid setup() { \r\n  size(200,200);\r\n}\r\n\r\nvoid draw() { \r\n  background(gs);\r\n  stroke(255); \r\n\r\n  \r\n  if (button) {\r\n    change = -5;\r\n    fill(255,0,0); \r\n  } else { \r\n    change = 5;\r\n    fill(0,0,255);\r\n  } \r\n  \r\n  \r\n  background(gs);\r\n  rect(x,y,w,h);\r\n  gs = gs + change;\r\n  gs = constrain(gs,0,254);\r\n}\r\n\r\nvoid mousePressed() { \r\n  if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h){\r\n\r\n  button = !button;\r\n  }\r\n  \r\n}\r\n<\/script><\/p>\n<h2>the code<\/h2>\n<p><code>\/\/ Dimmer Switch<br \/>\n\/\/ 2\/10\/11<\/p>\n<p>boolean button = false;<\/p>\n<p>int x = 50;<br \/>\nint y = 50;<br \/>\nint w = 100;<br \/>\nint h = 75;<br \/>\nfloat change = 5; \/\/ fade rate<br \/>\nfloat gs; \/\/greyscale<\/p>\n<p>void setup() {<br \/>\n  size(200,200);<br \/>\n}<\/p>\n<p>void draw() {<br \/>\n  background(gs);<br \/>\n  stroke(255); <\/p>\n<p>  if (button) {<br \/>\n    change = -5;<br \/>\n    fill(255,0,0);<br \/>\n  } else {<br \/>\n    change = 5;<br \/>\n    fill(0,0,255);<br \/>\n  } <\/p>\n<p>  background(gs);<br \/>\n  rect(x,y,w,h);<br \/>\n  gs = gs + change;<br \/>\n  gs = constrain(gs,0,254);<br \/>\n}<\/p>\n<p>void mousePressed() {<br \/>\n  if (mouseX > x && mouseX < x+w &#038;&#038; mouseY > y && mouseY < y+h){\n\n  button = !button;\n  }\n  \n}<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>the code \/\/ Dimmer Switch \/\/ 2\/10\/11 boolean button = false; int x = 50; int y = 50; int w = 100; int h = 75; float change = 5; \/\/ fade rate float gs; \/\/greyscale void setup() { &hellip; <a href=\"https:\/\/classes.visitsteve.com\/hacking\/dimmer-switch\/\">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-29","post","type-post","status-publish","format-standard","hentry","category-classnews"],"_links":{"self":[{"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/posts\/29","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=29"}],"version-history":[{"count":0,"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/posts\/29\/revisions"}],"wp:attachment":[{"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/media?parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/categories?post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/tags?post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}