//vars for button
boolean button =false;
int x= 0;
int y= 0;
int w= 400;
int h= 400;
//turn red & blue
float r = 255;
float g = 0;
float b = 255;
void setup() {
size (400, 400);
}
void draw() {
drawBackground();
//button
noStroke();
fill(0, 0, 0, 1);
rect(x, y, w, h);
}
void drawBackground() { //draws rectangular background with gradient using while loop
background(200);
noStroke();
float w=width/2;
float h=height*2;
int gColor=0;
while (w>0) {
noStroke();
fill(gColor);
rect(300, 0, w, h);
w=w-10; //sub. units from width of grads.
gColor=gColor+2; //changes color
}
//half way mark
stroke (255);
line (width/2, 0, width/2, height);
//lightsaber hilt pt.1
stroke(0);
fill(149, 143, 143);
rectMode(CENTER);
//200,300
rect(mouseX, mouseY+25, 15, 20);
//lightsaber hilt pt.2
stroke(0);
fill(149, 143, 143);
rectMode(CENTER);
rect(mouseX, mouseY, 20, 40);
//lightsaber hilt pt.3
stroke(0);
fill(111, 107, 107);
rectMode(CENTER);
rect(mouseX, mouseY-38, 18, 36);
//lightsaber hilt pt.4
stroke(0);
fill(111, 107, 107);
rectMode(CENTER);
rect(mouseX, mouseY-61, 12, 10);
// lightsaber hilt pt.5
stroke(0);
fill(111, 107, 107);
rectMode(CENTER);
rect(mouseX, mouseY-65, 16, 2);
// lightsaber hilt pt.6
stroke(0);
fill(178, 125, 25);
rectMode(CENTER);
rect(mouseX, mouseY-68.75, 14, 7);
// lightsaber hilt pt.7
stroke(0);
fill(178, 125, 25);
rectMode(CENTER);
rect(mouseX, mouseY-78, 8, 10);
// lightsaber hilt pt.8
stroke(0);
fill(149, 143, 143);
rectMode(CENTER);
rect(mouseX, mouseY-88, 18, 10);
// lightsaber hilt pt.9
stroke(0);
fill(149, 143, 143);
rectMode(CENTER);
rect(mouseX, mouseY-95, 20, 5);
// lightsaber hilt pt.10
stroke(0);
fill(149, 143, 143);
rectMode(CENTER);
rect(mouseX, mouseY-99, 24, 2);
//lightsaber hilt pt.11
stroke(0);
fill(149, 143, 143);
rectMode(CENTER);
rect(mouseX+15, mouseY-1, 10, 24);
//lightsaber hilt pt.12
stroke(216);
fill(149, 143, 143);
rectMode(CENTER);
rect(mouseX, mouseY-45, 22, 1);
//lightsaber hilt pt.13
stroke(216);
fill(149, 143, 143);
rectMode(CENTER);
rect(mouseX, mouseY-50, 22, 1);
//lightsaber hilt pt.14
stroke(216);
fill(149, 143, 143);
rectMode(CENTER);
rect(mouseX, mouseY-40, 22, 1);
//lightsaber hilt pt.15
stroke(216);
fill(149, 143, 143);
rectMode(CENTER);
rect(mouseX, mouseY-35, 22, 1);
//lightsaber hilt pt.16
stroke(216);
fill(149, 143, 143);
rectMode(CENTER);
rect(mouseX, mouseY-30, 22, 1);
//lightsaber hilt pt.17
stroke(216);
fill(149, 143, 143);
rectMode(CENTER);
rect(mouseX, mouseY-25, 22, 1);
//lightsaber hilt pt.18
stroke(216);
fill(149, 143, 143);
rectMode(CENTER);
rect(mouseX, mouseY-50, 22, 1);
// light saber (red)+button on and off
if (button) {
noStroke();
fill(r, g, b);
rectMode(CENTER);
rect(mouseX+1, mouseY-194, 6.5, 190);
} else {
noStroke();
fill(r, g, b);
}
//light saber tip+button on and off
if (button) {
noStroke();
fill(r, g, b);
ellipseMode(CENTER);
ellipse(mouseX+1, mouseY-290, 6.5, 5);
} else {
noStroke();
fill(r, g, b);
}
//lightsaber glow(tip)+button on and off
if (button) {
noStroke();
fill(r, g, b, 50);
ellipseMode(CENTER);
ellipse(mouseX+1, mouseY-290, 15, 10);
} else {
noStroke();
fill(r, g, b, 50);
}
//light saber glow (shaft)+button on and off
if (button) {
noStroke();
fill(r, g, b, 50);
rectMode(CENTER);
rect(mouseX+1, mouseY-194, 15, 190);
} else {
noStroke();
fill(r, g, b, 50);
}
// changes colour when you move side to side (jedi,sith)*
if (mouseX>width/2) {
r = r + 5; // speed at which the colors change when switching sides
} else {
r= r - 3;
}
if (mouseX>width/2) {
b = b - 5;
} else {
b = b + 3;
}
// dictates the color of the lightsaber when you move side to side
if (r>255) {// if r is greater than 255 then it'll stay red
r=255;
b=0;
} else if (r<0) { // if r is less than zero then it will turn blue
r=0;
b=255;
}
}
//turns button on and off (lightsaber on and off)
void mousePressed() {
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) {
button = !button;
}
}