INTERNET ART: networks, performative programming, and web as context

Button

Leave a comment

I still can’t take screen shots of my computer
Button on_button;
int clk = 1;

void setup() {
size (300, 150);
smooth();

// create the button object
on_button = new Button(“Counting is Fun!”, 20, 20, 100, 50);
}

void draw() {
float r = random(255);
float g = random(255);
float b = random(255);
color random = color(r,g,b);
if (on_button.MouseIsOver()) {
rect(200, 20, 50, 50);
background(255,0,0);
}
else {
background(0);
}

on_button.Draw();
}

// mouse button clicked
void mousePressed()
{
if (on_button.MouseIsOver()) {
background(fill);
fill(random);
frameRate(2);
print(“Clicked: “);
println(clk++);
}
}

// the Button class
class Button {
String label; // button label
float x; // top left corner x position
float y; // top left corner y position
float w; // width of button
float h; // height of button

// constructor
Button(String labelB, float xpos, float ypos, float widthB, float heightB) {
label = labelB;
x = xpos;
y = ypos;
w = widthB;
h = heightB;
}

void Draw() {
fill(218);
stroke(141);
rect(x, y, w, h, 10);
textAlign(CENTER, CENTER);
fill(0);
text(label, x + (w / 2), y + (h / 2));
}

boolean MouseIsOver() {
if (mouseX > x && mouseX < (x + w) && mouseY > y && mouseY < (y + h)) {
return true;
}
return false;
}
}

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s