// Made with http://processing.org // Copyleft Rene Christen, 2007 import krister.Ess.*; AudioChannel rightChannel; AudioChannel leftChannel; AudioChannel chairChannel; int x=25; int y; int xoff; boolean locked=true; PImage chair; PImage crowd; PImage puter; PImage pointer; PImage hand; PImage fist; void setup(){ size(500,150); chair = loadImage("chair.png"); crowd = loadImage("crowd.png"); puter = loadImage("puter.png"); pointer = loadImage("pointer.png"); hand = loadImage("hand.png"); fist = loadImage("fist.png"); y = 150 - chair.height; Ess.start(this); rightChannel=new AudioChannel("people.mp3"); rightChannel.pan(1); rightChannel.volume(0.5); rightChannel.play(Ess.FOREVER); leftChannel=new AudioChannel("typing.mp3"); leftChannel.pan(-1); leftChannel.play(Ess.FOREVER); chairChannel=new AudioChannel("chair.mp3"); noCursor(); } void draw(){ background(#ffffff); image(crowd,495 - crowd.width, 150 - crowd.height); image(chair,x,y); image(puter,-10,90); draw_cursor(); // drag chair if(locked==false && (mouseX - xoff)>=25){ x = mouseX - xoff; }else if (locked==true && x>25) { x-=3; } // start/stop typing if (x>25) { leftChannel.pause(); } else if (leftChannel.state==Ess.STOPPED && x<=25) { leftChannel.resume(); } chair_sound(); } void chair_sound() { if (x > 25) { float pan = float(x) / float(width/2) -1.0; if (pan <= 1) { chairChannel.pan(pan); } else if (pan > 1) { float volume = constrain((1.0 - (pan - 1.0)),0.0,1.0); pan = 1; chairChannel.pan(pan); chairChannel.volume(volume); } if (!mousePressed) chairChannel.play(Ess.FOREVER); } else if (x<=25) { chairChannel.stop(); } } void draw_cursor() { if (is_over() && !mousePressed) { image(hand,mouseX,mouseY);} else if (locked==false && mousePressed) { image(fist,mouseX,mouseY);} else { image(pointer,mouseX,mouseY);} } void mouseReleased() { locked=true; } void mousePressed() { if (is_over()) { xoff = mouseX - x; locked = false; } else { locked = true; } } boolean is_over(){ if (mouseX > x && mouseX < (x + chair.width) && mouseY > y && mouseY < (y + chair.height)){ return true; } else { return false; } } public void stop() { Ess.stop(); super.stop(); }