Interactivity using buttons
Just as an experiment i tried creating buttons which change the colour of the background. Unfortunately i couldnt upload the application so it is just an image, but i assure it does work! heres the code if you dont beleive me...you cynical swine... :]
code -
void setup()
{
size(100,100);
framerate(100);
}
void draw()
{
println(mouseX);
println(mouseY);
//button 1 blue
fill(0,0,255);
rect(20,20,10,10);
if(mouseX<30 && mouseX > 20 )
if(mouseY<30 && mouseY > 20 )
if(mousePressed == true)
background(0,0,255);
//button 2 red
fill(255,0,0);
rect(70,20,10,10);
if(mouseX<80 && mouseX > 70 )
if(mouseY<30 && mouseY > 20 )
if(mousePressed == true)
background(255,0,0);
//button 2 red
fill(255,255,0);
rect(20,70,10,10);
if(mouseX < 30 && mouseX > 20 )
if(mouseY < 80 && mouseY > 70 )
if(mousePressed == true)
background(255,255,0);
//button 4 green
fill(0,255,0);
rect(70,70,10,10);
if(mouseX < 80 && mouseX > 70 )
if(mouseY < 80 && mouseY > 70 )
if(mousePressed == true)
background(0,255,0);
//button 5 centre
fill(0,0,0);
rect(45,45,10,10);
if(mouseX < 55 && mouseX > 45 )
if(mouseY < 55 && mouseY > 45 )
if(mousePressed == true)
background(random(255),random(255),random(255));
//? for button 5
//PFont font;
//font = loadFont("arial.ttf");
//textFont(font, 12);
//String s = "The quick brown fox jumped over the lazy dog.";
//text(s, 15, 20, 70, 70);
{
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment