Making a clickable button

Hi! I am very new to processing and have an assignment for a class that is making a button that when clicked twice it turns from inactive (black color) to active (green color) and when clicked 4 times after this it turns back to inactive. Right now I can't seem to figure out how to get the button or the sketch in general to track how many times the button has been clicked. I have tried making a variable that would represent how many times the mouse has been pressed but I am missing something. Our professor told us to assign mousePressed to a variable and then perform a test each time it is clicked with a conditional statement. Here is the code I have so far

int rectX = 300;

int rectY = 200; //Position of square button

int rectSize = 200; //Size of button

int mouseClicked; //Number count

color inactiveColor;

color activeColor;

void setup() {

size( 600, 400 );

inactiveColor = color( 0 );

activeColor= color( 62, 211, 95 );

println( mouseClicked );


void draw() {

background( 150 );

rectMode( CENTER );

fill( inactiveColor );

rect( rectX, rectY, rectSize, rectSize );


Do I seem like I am on the right path? If not can someone steer me in the right path and give me a couple pointers on how to make this variable work and implement it into a conditional statement? I am also puzzled when it comes to how I will determine whether the mouse is clicking inside the button. I know I will have to use a conditional statement but I am just confused. Thanks to anyone who can help!


Sign In or Register to comment.