Friday, March 20, 2009

How create buttons in Processing (example)

int inside = -1; // flag for know if show or not show the other rectangle; -1 = no show ; 1 = show
int bx=400; // position in X of the up corner of the botton
int by=300; // position in Y of the up corner of the botton

void setup()
{
size(800,600);
}

void draw()
{
background(0);
rect(400,300,60,60); // Our Button in the position (400,300) with size of 60 pixels by 60 pixels
if(inside==1)rect(10,10,100,100); // acction that have to happend when we press the button
}
void mousePressed(){
if(!(((mouseX > ( bx+60))||(mouseY > (by+60)))||((mouseX < bx)||(mouseY < by))))inside=inside*-1; // condition to know if we do clik inside the button
}

2 comments: