/////////////////////////
///Mad Science Machine///
/////by Devan Boone//////
/////////////////////////
///////////////////////////////////////////////////////
//////far left lever controlls power and lightbulb/////
/////////second from left powers up tesla coil/////////
//purple button releases rainbow bubbles from exhaust//
//////////green button reveals small claw//////////////
///////////////////////////////////////////////////////
//variables for lightbulb colour
float filamentR = 0;
float filamentG = 0;
float bulbB = 180;
// variables dictating Claw location and dropped bottle
float clawSpring1X = 120;
float clawSpring2X = 115;
float clawBladeX;
float clawBlade1Y=255;
float clawBlade2Y=245;
float bottleY;
float bottleX;
float doorCorner1X = 100;
float doorCorner2X = 120;
boolean doorOpen = false;
//variables for exhaust bubbles
float bubble1X = random(70, 110);
float bubble1Y = random(310, 350);
float bubble2X = random(70, 110);
float bubble2Y = random(310, 350);
float bubble3X = random(70, 110);
float bubble3Y = random(310, 350);
float bubble4X = random(70, 110);
float bubble4Y = random(310, 350);
float bubbleMovement1Y = random(-3, 0);
float bubbleMovement2Y = random(-4, 0);
float bubbleMovement3Y = random(-4, 0);
float bubbleMovement4Y = random(-4, 0);
//universal timer variables
float startTimeBubble = 0;
float startTimeLever = 0;
float startTimeClaw = 0;
float startTimeBolt = 0;
//variables dictating tesla coil
float teslaBolt1X;
float teslaBolt2X;
float teslaBolt1Y;
float teslaBolt2Y;
float teslaBoltVariance1X;
float teslaBoltVariance2X;
float teslaBoltVariance1Y;
float teslaBoltVariance2Y;
float teslaOrigin;
//on off boolean
boolean machineActive = false;
boolean teslaIsOn = false;
boolean bubbleOut = false;
//location variables for use in activatable buttons
float exhaustButtonCorner1X = 150;
float exhaustButtonCorner1Y = 130;
float exhaustButtonCorner2X = 160;
float exhaustButtonCorner2Y = 140;
float doorButtonCorner1X = 150;
float doorButtonCorner1Y = 160;
float doorButtonCorner2X = 160;
float doorButtonCorner2Y = 170;
float teslaLeverCorner1X = 120;
float teslaLeverCorner1Y = 130;
float teslaLeverCorner2X = 140;
float teslaLeverCorner2Y = 170;
float teslaLeverY = 12.5;
float activationLeverCorner1X = 100;
float activationLeverCorner1Y = 130;
float activationLeverCorner2X = 110;
float activationLeverCorner2Y = 170;
float activationLeverOrientationY = -20;
void setup() {
size(400, 400);
//define bolts random start positions
teslaBolt1X = random(165, 265);
teslaBolt2X = random(165, 265);
teslaBolt1Y = random(25, 105);
teslaBolt2Y = random(25, 105);
teslaBoltVariance1X = random(-5, 5);
teslaBoltVariance2X = random(-5, 5);
teslaBoltVariance1Y = random(-5, 5);
teslaBoltVariance2Y = random(-5, 5);
}
void draw() {
background(30, 23, 18);
drawMachine();
machineActivate();
teslaLever();
exhaustButton();
doorButton();
}
void drawMachine() {
//remove stroke
noStroke();
// define colour for Exhaust pipes
fill(125, 114, 92);
// draw Exhaust pipes
quad(300, 240, 280, 220, 310, 160, 340, 160);
quad(250, 220, 260, 220, 260, 200, 250, 190);
//define colour for exaust opening
fill(110, 102, 80);
//draw exhaust opening
quad(340, 160, 310, 160, 300, 140, 360, 120);
//define colour for main machine body
fill(86, 107, 135);
//define Shapes for main body
rectMode(CORNERS);
rect(100, 220, 200, 320);
rect(220, 220, 300, 320);
rect(80, 120, 180, 180);
rect(100, 320, 300, 400);
triangle(100, 320, 20, 400, 100, 400);
triangle(300, 320, 300, 400, 380, 400);
//define colour for tesla coil rod and control panel stands
fill(158, 171, 189);
//draw tesla coil rod
rect(210, 90, 220, 320);
//draw control panel stands
rect(100, 180, 105, 220);
rect(115, 180, 120, 220);
rect(140, 180, 145, 220);
rect(155, 180, 160, 220);
quad(165, 220, 170, 220, 180, 180, 175, 180);
quad(100, 230, 100, 240, 80, 180, 85, 180);
//define Tesla coil colour 1
fill(174, 164, 143);
//draw tesla coil part 1
ellipseMode(CORNERS);
ellipse(170, 70, 260, 100);
ellipse(170, 30, 260, 60);
// define Tesla coil colour 2
fill(194, 183, 163);
//draw tesla coil part 2
ellipse(160, 50, 270, 80);
//define coil pattern colour
fill(145, 124, 112);
//draw coil pattern using simple loop
for (int n = 110; n<210; n+=20) {
ellipse(200, n, 230, n+10);
}
//////Draw Opening Door////////
//define shadow colour
fill(46, 57, 65);
//draw door shadow
rect(100, 240, 120, 260);
//draw open door if door open boolean is true
if (doorOpen == true) {
fill( 106, 127, 155);
rect(doorCorner1X, 240, doorCorner2X, 260);
}
//define claw spring colour
fill(131, 123, 94);
//draw Claw spring
quad(clawSpring1X, 250, clawSpring1X-2, 250, clawSpring1X-((clawSpring1X-clawSpring2X)/4)-2, 240, clawSpring1X-((clawSpring1X-clawSpring2X)/4), 240);
quad(clawSpring1X, 250, clawSpring1X-2, 250, clawSpring1X-((clawSpring1X-clawSpring2X)/4)-2, 260, clawSpring1X-((clawSpring1X-clawSpring2X)/4), 260);
quad(clawSpring1X-((clawSpring1X-clawSpring2X)/4), 240, clawSpring1X-((clawSpring1X-clawSpring2X)/4)-2, 240, clawSpring1X-((clawSpring1X-clawSpring2X)/2)-2, 250, clawSpring1X-((clawSpring1X-clawSpring2X)/2), 250);
quad(clawSpring1X-((clawSpring1X-clawSpring2X)/4), 260, clawSpring1X-((clawSpring1X-clawSpring2X)/4)-2, 260, clawSpring1X-((clawSpring1X-clawSpring2X)/2)-2, 250, clawSpring1X-((clawSpring1X-clawSpring2X)/2), 250);
quad(clawSpring1X-((clawSpring1X-clawSpring2X)/2)-2, 250, clawSpring1X-((clawSpring1X-clawSpring2X)/2), 250, (clawSpring1X-((clawSpring1X-clawSpring2X)/2)-((clawSpring1X-clawSpring2X)/4)), 240, (clawSpring1X-((clawSpring1X-clawSpring2X)/2)-((clawSpring1X-clawSpring2X)/4))-2, 240);
quad(clawSpring1X-((clawSpring1X-clawSpring2X)/2)-2, 250, clawSpring1X-((clawSpring1X-clawSpring2X)/2), 250, (clawSpring1X-((clawSpring1X-clawSpring2X)/2)-((clawSpring1X-clawSpring2X)/4)), 260, (clawSpring1X-((clawSpring1X-clawSpring2X)/2)-((clawSpring1X-clawSpring2X)/4))-2, 260);
quad((clawSpring1X-((clawSpring1X-clawSpring2X)/2)-((clawSpring1X-clawSpring2X)/4)), 240, (clawSpring1X-((clawSpring1X-clawSpring2X)/2)-((clawSpring1X-clawSpring2X)/4))-2, 240, clawSpring2X-2, 250, clawSpring2X, 250);
quad((clawSpring1X-((clawSpring1X-clawSpring2X)/2)-((clawSpring1X-clawSpring2X)/4)), 260, (clawSpring1X-((clawSpring1X-clawSpring2X)/2)-((clawSpring1X-clawSpring2X)/4))-2, 260, clawSpring2X-2, 250, clawSpring2X, 250);
//define claw colour
fill(192, 208, 229);
//keep clawBlade linked to spring
clawBladeX = clawSpring2X-15;
//draw claw
triangle(clawBladeX, clawBlade1Y, clawBladeX+10, 260, clawSpring2X, 250);
triangle(clawBladeX, clawBlade2Y, clawBladeX+10, 240, clawSpring2X, 250);
//draw closed door if doorOpen boolean is false
if (doorOpen == false) {
fill( 106, 127, 155);
rect(doorCorner1X, 240, doorCorner2X, 260);
}
//////Draw Lightbulb////////
// define colour for lightbulb connection
fill(100);
//drawlightbulb conection
rect(100, 110, 110, 120);
//define filament stroke
stroke(filamentR, filamentG, 0);
strokeWeight(2);
//draw filaments
line(105, 100, 105, 110);
line(105, 100, 95, 100);
line(95, 100, 95, 90);
line(95, 90, 102, 90);
line(102, 90, 102, 95);
line(102, 95, 107, 95);
line(107, 95, 107, 90);
line(115, 90, 107, 90);
line(115, 90, 115, 95);
//define bulb colour
noStroke();
fill(255, 200, bulbB, 120);
//draw bulb
ellipse(85, 75, 125, 115);
/////Draw Controls///////
//define colour for the activation Lever base
fill(72, 87, 105);
//define stroke for the activation Lever base
stroke(165, 0, 0);
strokeWeight(1);
//draw activation Lever base
rect(activationLeverCorner1X, activationLeverCorner1Y, activationLeverCorner2X, activationLeverCorner2Y);
//define stroke for lever
stroke(163, 176, 194);
strokeWeight(2);
//draw activation lever
line(105, 150+activationLeverOrientationY, 105, 150+(activationLeverOrientationY/2));
line(101, 150+(activationLeverOrientationY/2), 109, 150+(activationLeverOrientationY/2));
line(101, 150+(activationLeverOrientationY/2), 101, 150);
line(109, 150+(activationLeverOrientationY/2), 109, 150);
//define colour for Tesla Lever Base
fill(72, 87, 105);
//define stroke for Tesla Lever Base
strokeWeight(1);
stroke(165, 165, 0);
//draw Lever Base
rect(teslaLeverCorner1X, teslaLeverCorner1Y, teslaLeverCorner2X, teslaLeverCorner2Y);
//define lever track colour
noStroke();
fill(42, 57, 75);
//draw tesla lever track
rect(128, 135, 132, 165);
// define tesla Lever Colour
fill(0, 0, 165);
//draw tesla Lever
rect(121, 147.5+teslaLeverY, 139, 147.5+(teslaLeverY+5));
//define Exhaust button colour
fill(165, 0, 165);
// define button stroke
stroke(50);
strokeWeight(1);
//draw Exhaust button
rect(exhaustButtonCorner1X, exhaustButtonCorner1Y, exhaustButtonCorner2X, exhaustButtonCorner2Y);
//define door button colour
fill(0, 165, 0);
//draw door button
rect(doorButtonCorner1X, doorButtonCorner1Y, doorButtonCorner2X, doorButtonCorner2Y);
}
void machineActivate() {
//debug tool
println("machineActive = " + machineActive);
//check mouse is pressing the activation lever
if (mousePressed) {
if (mouseX >= activationLeverCorner1X && mouseX<=activationLeverCorner2X) {
if (mouseY >= activationLeverCorner1Y && mouseY<=activationLeverCorner2Y) {
//if the machine is off do inside
if (machineActive == false) {
//prevent rapid reading
if (millis()>startTimeLever+100) {
//turn on bulb by changing colour variables
bulbB = 0;
filamentR=255;
filamentG=150;
//flip lever down for on
activationLeverOrientationY=20;
//reset timer to keep track of next button press
resetTimerLever();
//store machine state
machineActive = true;
}
} else {
//prevent rapid reading
if (millis()>startTimeLever+100) {
//turn off bulb by manipulating colour
bulbB=120;
filamentR=0;
filamentG=0;
//flip lever up for off
activationLeverOrientationY=-20;
//reset timer to keep track of next button press
resetTimerLever();
//store machine state
machineActive = false;
}
}
}
} else {
}
}
}
void teslaLever() {
//debug tool
println("teslaLeverY = " + teslaLeverY+" teslaIsOn = " + teslaIsOn);
//check mouse is over tesla Lever
if (mousePressed) {
if (mouseX >= teslaLeverCorner1X && mouseX <= teslaLeverCorner2X) {
if (mouseY >= teslaLeverCorner1Y && mouseY <= teslaLeverCorner2Y) {
if (teslaIsOn == false) {
//prevent rapid reading
if (millis()>startTimeLever+100) {
//reorient Lever
teslaLeverY = -12.5;
//reset timer for preventing rapid read
resetTimerLever();
//store Tesla State
teslaIsOn = true;
}
} else if (teslaIsOn) {
//prevent rapid reading
if (millis()>startTimeLever+100) {
//reorient Lever
teslaLeverY = 12.5;
//reset timer for preventing rapid read
resetTimerLever();
//store tesla State
teslaIsOn = false;
}
}
}
}
}
//only run code if both machine and tesla are on
if (machineActive) {
if (teslaIsOn) {
fill(200, 140, 255, random(50, 150));
noStroke();
//draw tesla coil part 1
ellipseMode(CORNERS);
ellipse(160, 30, 270, 100);
//draw coil pattern using simple loop
for (int n = 110; n<210; n+=20) {
ellipse(200, n, 230, n+10);
}
if (millis()>startTimeBolt+200) {
//every 200 millis vary the position of the bolts
teslaBolt1X = random(165, 265);
teslaBolt2X = random(165, 265);
teslaBolt1Y = random(25, 105);
teslaBolt2Y = random(25, 105);
resetTimerBolt();
}
//keep the center of the bolts moving
teslaBoltVariance1X = random(-15, 15);
teslaBoltVariance2X = random(-15, 15);
teslaBoltVariance1Y = random(-15, 15);
teslaBoltVariance2Y = random(-15, 15);
//define bolt colour
stroke(240, 220, 255);
strokeWeight(2);
//draw bolt
line(teslaBolt1X, teslaBolt1Y, ((teslaBolt1X+((teslaBolt2X-teslaBolt1X)/2))+teslaBoltVariance1X), ((teslaBolt1Y+((teslaBolt2Y-teslaBolt1Y)/2))+teslaBoltVariance1Y));
line(teslaBolt2X, teslaBolt2Y, ((teslaBolt2X-((teslaBolt2X-teslaBolt1X)/2))+teslaBoltVariance2X), ((teslaBolt2Y-((teslaBolt2Y-teslaBolt1Y)/2))+teslaBoltVariance2Y));
line(((teslaBolt1X+((teslaBolt2X-teslaBolt1X)/2))+teslaBoltVariance1X), ((teslaBolt1Y+((teslaBolt2Y-teslaBolt1Y)/2))+teslaBoltVariance1Y), ((teslaBolt2X-((teslaBolt2X-teslaBolt1X)/2))+teslaBoltVariance2X), ((teslaBolt2Y-((teslaBolt2Y-teslaBolt1Y)/2))+teslaBoltVariance2Y));
}
}
}
void exhaustButton() {
//make sure to only work when the machine lever is up
if (machineActive) {
//create variable for pseudo gravity
float bubbleMovementChange1Y = random(0,0.2);
float bubbleMovementChange2Y = random(0,0.2);
float bubbleMovementChange3Y = random(0,0.2);
float bubbleMovementChange4Y = random(0,0.2);
//bubble X movement defined
if (bubbleOut) {
if (bubble1X>20) {
bubble1X-=random(5);
}
if (bubble1X>70) {
bubble2X-=random(5);
}
if (bubble1X>230) {
bubble3X-=random(5);
}
if (bubble1X>150) {
bubble4X-=random(5);
}
//define bubble y movement
bubble1Y+=bubbleMovement1Y;
bubble2Y+=bubbleMovement2Y;
bubble3Y+=bubbleMovement3Y;
bubble4Y+=bubbleMovement4Y;
//pseudo gravity effect
bubbleMovement1Y+=bubbleMovementChange1Y;
bubbleMovement2Y+=bubbleMovementChange2Y;
bubbleMovement3Y+=bubbleMovementChange3Y;
bubbleMovement4Y+=bubbleMovementChange4Y;
//create warping colour
fill(random(100,255), random(100,255), random(100,255), 150);
noStroke();
//draw bubbles
ellipseMode(CENTER);
ellipse(bubble1X, bubble1Y, 50, 50);
ellipse(bubble2X, bubble2Y, 50, 50);
ellipse(bubble3X, bubble3Y, 50, 50);
ellipse(bubble4X, bubble4Y, 50, 50);
if (millis()>startTimeBubble+5000) {
resetTimerBubble();
bubbleOut = false;
}
}
if (mousePressed) {
if (mouseX >= exhaustButtonCorner1X && mouseX<=exhaustButtonCorner2X) {
if (mouseY >= exhaustButtonCorner1Y && mouseY<=exhaustButtonCorner2Y) {
if (bubbleOut==false) {
resetTimerBubble();
bubbleOut = true;
bubbleMovementChange1Y = random(5);
bubbleMovementChange2Y = random(5);
bubbleMovementChange3Y = random(5);
bubbleMovementChange4Y = random(5);
bubbleMovement1Y = random(-10, 0);
bubbleMovement2Y = random(-10, 0);
bubbleMovement3Y = random(-10, 0);
bubbleMovement4Y = random(-10, 0);
bubble1Y = random(70, 110);
bubble1X = random(310, 350);
bubble2Y = random(70, 110);
bubble2X = random(310, 350);
bubble3Y = random(70, 110);
bubble3X = random(310, 350);
bubble4Y = random(70, 110);
bubble4X = random(310, 350);
}
}
}
}
}
}
void doorButton() {
float clawSpringMovement = -1;
if (machineActive) {
if (doorOpen) {
doorCorner2X = 80;
if(millis()<startTimeClaw+3000){
if (clawSpring2X>70) {
clawSpring2X +=clawSpringMovement;
}
}
if (millis()>startTimeClaw+3000) {
if (clawSpring2X<115){
clawSpring2X-=(clawSpringMovement)*2;
}
if(millis()>startTimeClaw+3500){
resetTimerClaw();
doorOpen = false;
doorCorner2X = 120;
clawSpring2X = 115;
}
}
}
if (mousePressed) {
if (mouseX >= doorButtonCorner1X && mouseX<=doorButtonCorner2X) {
if (mouseY >= doorButtonCorner1Y && mouseY<=doorButtonCorner2Y) {
if (doorOpen == false) {
doorOpen = true;
resetTimerClaw();
}
}
}
}
}
}
void resetTimerBubble() {
startTimeBubble = millis();
}
void resetTimerLever() {
startTimeLever = millis();
}
void resetTimerClaw() {
startTimeClaw = millis();
}
void resetTimerBolt() {
startTimeBolt = millis();
}