int lightLv = 0;
Serial myPort;
PFont myFont;
float heatPercent = .22222;
float thermHeight = 500;
boolean playing = true;
PImage img;

void setup(){
size(800, 800);
myFont = createFont("Helvetica", 40);
textFont(myFont);
frameRate(15);

println(Serial.list()); //print all availabe ports

myPort = new Serial(this, Serial.list()[0], 9600);

myPort.buffer(1);
}


void draw(){

if(playing){
background(120);
if(lightLv < 85){
heatPercent -= .0005;
}else{
heatPercent += .0035;
}

if (heatPercent < 0){
heatPercent = 0;
}
if (heatPercent > 1){
playing = false;
}

fill(255);
noStroke();
ellipseMode(CENTER);
ellipse(400, 150, 79, 79);
rect(360, 650, 80, -thermHeight);
fill(0,0,255);

ellipse(400, 650, 120, 120);
rect(360, 650, 80, -thermHeight*heatPercent);

}
if (!playing){
img = loadImage("penguins.jpg");
background(img);
text("Enjoy the long walk home alone.", 100, 650);
text ("Click the Window to Play Again", 100, 700);
}

}

void serialEvent(Serial myPort){
byte[] myData = myPort.readBytes();
lightLv = int(myData[0]);
}

void mousePressed(){
if(!playing && mouseX> 0 && mouseX< 800 && mouseY> 0 && mouseY< 800){
playing = !playing;
heatPercent = .2;
}
}