Random Line Maker

the code


// Random Line Maker
// I wanted to connect the lines, but I will come back to that idea

// declare variables
//colors
float r;
float g;
float b;
float a;

//construction
float startX = width/2;
float startY = height;
float endX;
float endY;

void setup() {
size(400,400);
background(255);
smooth();
}
void draw() {
// pick a random color
r = random(255);
g = random(255);
b = random(255);
a = random(255);

startX = random(width);
startY = random(height);
endX = random(width);
endY = random(height);

// create a random colored line of random dimensions
stroke(r,g,b,a);
line(startX,startY,endX,endY);

}

// if the mouse is pressed, redraw the background
void mousePressed() {
background(255);
}

Dimmer Switch

the code

// Dimmer Switch
// 2/10/11

boolean button = false;

int x = 50;
int y = 50;
int w = 100;
int h = 75;
float change = 5; // fade rate
float gs; //greyscale

void setup() {
size(200,200);
}

void draw() {
background(gs);
stroke(255);

if (button) {
change = -5;
fill(255,0,0);
} else {
change = 5;
fill(0,0,255);
}

background(gs);
rect(x,y,w,h);
gs = gs + change;
gs = constrain(gs,0,254);
}

void mousePressed() {
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h){ button = !button; } }

dimmer button draft

my code


// Dimmer Button
// I have a feeling this fade could be done better...

// declare and initialize variables
boolean button = false;
int x = 50;
int y = 50;
int w = 100;
int h = 75;
float change = 5; // fade rate
float gs; //greyscale from 0-255

void setup() {
size(200,200);
}

void draw() {
background(gs);
stroke(255);

// if mouse is pressed over the button
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h && mousePressed) { button = true; } else { button = false; } // this is the fade if (button) { change = -5; fill(255,0,0); } else { change = 5; fill(0,0,255); } background(gs); rect(x,y,w,h); gs = gs + change; // this creates the fade // declaring my constraints gs = constrain(gs,0,254); }