Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Button Simple
- * Language: p5
- * @Author: Allen Thoe
- */
- //Global Variables
- var x, y;
- var grey;
- var showRect;
- var count;
- function setup() {
- createCanvas(400, 400);
- x = 60;
- y = 100;
- grey = 255;
- showRect = false; //Boolean -- 1 or 0
- count = 0;
- }
- function draw() {
- background(220);
- fill(grey); //Color of ellipse
- if(abs(mouseX - x) < 40 && abs(mouseY - y) < 20){
- //INSIDE THE BUTTON
- grey = 100;
- if(mouseIsPressed){
- //DO SOMETHING
- showRect = true;
- //count++;
- }
- } else {
- grey = 255;
- }
- ellipse(x, y, 80, 40); //rect(x, y, width, height, round)
- fill(0); //Black text
- text("Click Me", x-20, y+5);
- if(showRect){
- rect(220, 240, 100, 40);
- fill(255);
- text("Count: " + count, 220, 280);
- }
- }
- /* When mouse button is released, this is executed*/
- function mouseClicked(){
- count++;
- }
Add Comment
Please, Sign In to add comment