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

Counting is fun

Leave a comment

int xPos=200;
float w = 300;
float h = 150;
String n = “No, it’s really not!”;
float textX = 0;
float textY = h/2;
float textS = 10;
float textH = 15;
float speed = 4;

Button on_button;
int clk = 1;

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

}

void draw() {

on_button = new Button(“Counting is Fun!”, 20, 20, 100, 50);

if (on_button.MouseIsOver()) {
rect(200, 20, 50, 50);
background(100,0,0);
}
else {
background(0,100,100);
}
if(mouseX < width/3){
background(30,100,120);
}
else if(mouseX > width/3 && mouseX < 2*(width/3)){
background(0,200,0);
}
else{
background(0,0,255);
}
line(width/3,0, width/3,height);
line(2*(width/3),0, 2*(width/3), height);

float r = random(255);
float g = random(255);
float b = random(255);
color random = color(r,g,b);
fill(random);
textSize(textH);
text(n, textX, textY);

textX=textX + speed;

if (textX > width || textX < 0){
speed = speed * -1;
}
else if (xPos >width+20){
xPos=-20;
}
on_button.Draw();
}
// mouse button clicked
void mousePressed()
{
if (on_button.MouseIsOver()) {
background(200,0,200);
frameRate(25);

float r = random(255);
float g = random(255);
float b = random(255);
color random = color(r,g,b);
fill(random);
strokeWeight(7);

ellipse(xPos, 200, 40, 40);
xPos=xPos+1;
ellipse(xPos, 100, 40, 40);
xPos=xPos+1;
line(width/2,0,width/2,height);
line(0,height/2, width, height/2);
print(“Clicked: “);
println(clk++);
}
}
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
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