{"id":28,"date":"2011-02-12T04:32:12","date_gmt":"2011-02-12T04:32:12","guid":{"rendered":"http:\/\/classes.visitsteve.com\/hacking\/?p=28"},"modified":"2011-02-12T04:32:12","modified_gmt":"2011-02-12T04:32:12","slug":"dimmer-button-draft","status":"publish","type":"post","link":"https:\/\/classes.visitsteve.com\/hacking\/dimmer-button-draft\/","title":{"rendered":"dimmer button draft"},"content":{"rendered":"<p><script type=\"application\/processing\">\r\n\/\/Info: http:\/\/processingjs.org\/reference\r\n\/\/ Dimmer Button\r\n\/\/ I have a feeling this fade could be done better...\r\n\r\n\/\/ declare and initialize variables\r\nboolean button = false;\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 from 0-255\r\n\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  \/\/ if mouse is pressed over the button\r\n  if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h && mousePressed) {\r\n    button = true;\r\n  } else {\r\n    button = false;\r\n  }\r\n  \r\n  \/\/ this is the fade\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; \/\/ this creates the fade\r\n  \r\n  \/\/ declaring my constraints\r\n  gs = constrain(gs,0,254);\r\n}\r\n<\/script><\/p>\n<h2>my code<\/h2>\n<p><code><br \/>\n\/\/ Dimmer Button<br \/>\n\/\/ I have a feeling this fade could be done better...<\/p>\n<p>\/\/ declare and initialize variables<br \/>\nboolean button = false;<br \/>\nint x = 50;<br \/>\nint y = 50;<br \/>\nint w = 100;<br \/>\nint h = 75;<br \/>\nfloat change = 5; \/\/ fade rate<br \/>\nfloat gs; \/\/greyscale from 0-255<\/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 mouse is pressed over the button<br \/>\n  if (mouseX > x && mouseX < x+w &#038;&#038; mouseY > y && mouseY < y+h &#038;&#038; mousePressed) {\n    button = true;\n  } else {\n    button = false;\n  }\n  \n  \/\/ this is the fade\n  if (button) {\n    change = -5;\n    fill(255,0,0); \n  } else { \n    change = 5;\n    fill(0,0,255);\n  } \n  \n  \n  background(gs);\n  rect(x,y,w,h);\n  gs = gs + change; \/\/ this creates the fade\n  \n  \/\/ declaring my constraints\n  gs = constrain(gs,0,254);\n}<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>my code \/\/ Dimmer Button \/\/ I have a feeling this fade could be done better&#8230; \/\/ declare and initialize variables boolean button = false; int x = 50; int y = 50; int w = 100; int h = &hellip; <a href=\"https:\/\/classes.visitsteve.com\/hacking\/dimmer-button-draft\/\">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-28","post","type-post","status-publish","format-standard","hentry","category-classnews"],"_links":{"self":[{"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/posts\/28","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=28"}],"version-history":[{"count":0,"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/posts\/28\/revisions"}],"wp:attachment":[{"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/media?parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/categories?post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/classes.visitsteve.com\/hacking\/wp-json\/wp\/v2\/tags?post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}