MrThoe

Tutoring

Sep 22nd, 2020 (edited)
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** Button Simple
  2.   *
  3.   * @Author: Allen Thoe
  4.   */
  5.  
  6. //Global Variables
  7. var x, y, w, h;
  8. var grey;
  9. var showRect;
  10. var count;
  11.  
  12. function setup() {
  13.   createCanvas(400, 400);
  14.   x = 250;
  15.   y = 100;
  16.   w = 80;
  17.   h = 40;
  18.   grey = 255;
  19.   showRect = false;  //Boolean  -- 1 or 0
  20.   count = 0;
  21. }
  22.  
  23. function draw() {
  24.   background(220);
  25.   fill(grey);  //Color of ellipse
  26.   if(abs(mouseX - x) < w/2 && abs(mouseY - y) < h/20){
  27.     //INSIDE THE BUTTON
  28.     grey = 100;
  29.     if(mouseIsPressed){
  30.       //DO SOMETHING
  31.       showRect = true;
  32.       //count++;
  33.     }
  34.   } else {
  35.     grey = 255;
  36.   }
  37.   ellipse(x, y, w, h);  //rect(x, y, width, height, round)
  38.   fill(0);  //Black text
  39.   text("Click Me", x-20, y+5);
  40.   if(showRect){
  41.     rect(220, 240, 100, 40);
  42.     fill(255);
  43.     text("Count: " + count, 220, 280);
  44.   }
  45.   text(mouseX, 10, 20);
  46. }
  47.  
  48. /* When mouse button is released, this is executed*/
  49. function mouseClicked(){
  50.   count++;
  51. }
Add Comment
Please, Sign In to add comment