MrThoe

Simple Button

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