Candle[] candles = new Candle[9]; Shamash s; Shamash hiddenS; void setup(){ size(500,500); frameRate(20); makeCandles(); } void makeCandles(){ for(int i = 0; i < 4; i++){ candles[i] = new Candle(36+(i*50),120); candles[i+4] = new Candle(284+(i*50),120); } hiddenS = new Shamash();//null; candles[8] =new Candle(hiddenS); s = null; // s = null; } void reset(){ makeCandles(); } boolean virgin = true; void keyPressed(){ if(key == ' '){ makeCandles(); } } void draw(){ background(0,56,184); noFill(); strokeWeight(36); stroke(0); drawMenorah(); strokeWeight(20); stroke(200); drawMenorah(); for(int i = 0; i < candles.length; i++){ if(candles[i] != null){ candles[i].draw(); } } if(s != null){ s.move(); s.draw(); } } void mousePressed(){ s = new Shamash(candles[8]); candles[8] = null; } void mouseReleased(){ candles[8] = new Candle(s); s = null; } void mousePressed(){ if(s == null){ s = new Shamash(candles[8]); candles[8] = null; } else { candles[8] = new Candle(s); s = null; } } void drawMenorah(){ rect(246,200,8,200); rect(220,400,60,20); arc(250, 200, 400,200, PI/2, PI); arc(250, 200, 300,160, PI/2, PI); arc(250, 200, 200,120, PI/2, PI); arc(250, 200, 100,80, PI/2, PI); arc(250, 200, 400,200, 0, PI/2); arc(250, 200, 300,160, 0, PI/2); arc(250, 200, 200,120, 0, PI/2); arc(250, 200, 100,80, 0, PI/2); } class Shamash{ color c = color(random(128,255),random(128,255),random(128,255)); float x = 10; float y = 20; Shamash(){ } Shamash(Candle c){ this.c = c.c; } void move(){ x = mouseX -5; y = mouseY - 10; for(int i = 0; i < 8; i++){ Candle c = candles[i]; if(isNear(c)){ c.lit = true; } } } boolean isNear(Candle c) { if(c == null) return false; float cx = c.x + 14; float cy = c.y - 20; return (dist(x,y,cx,cy) < 20); } void draw(){ pushMatrix(); translate(x,y); pushMatrix(); float a = atan2(y-100,x-250); rotate(a-PI/2); translate(-15,20); strokeWeight(4); stroke(0); fill(c); rect(0,0,30,80); line(14,0,14,-20); popMatrix(); noStroke(); fill(255,200,0); float s = random(20,40); ellipse(0,0,16,s); popMatrix(); stroke(255); strokeWeight(2); } } class Candle{ float x,y; color c; boolean lit = false; Candle(Shamash s){ this.c = s.c; this.x = 236; this.y = 112; lit = true; } Candle(float x,float y){ this.x = x; this.y = y; this.c = color(random(128,255),random(128,255),random(128,255)); } void draw(){ strokeWeight(4); stroke(0); fill(c); rect(x,y,30,80); line(x+14,y-1,x+14,y-20); if(lit) { noStroke(); fill(255,200,0); float s = random(20,40); ellipse(x+14,y-s/2-8,16,s); } } }