|
|
|
import controlP5.ControlEvent;
|
|
|
|
import processing.core.*;
|
|
|
|
|
|
|
|
public class EuglenaApplet extends PApplet {
|
|
|
|
final int cameraMode = 9;
|
|
|
|
final int whichArduino = 0;
|
|
|
|
|
|
|
|
// Hardware
|
|
|
|
ProjectorApplet projectorApplet;
|
|
|
|
Camera camera;
|
|
|
|
LEDControl ledControl;
|
|
|
|
|
|
|
|
// Software components
|
|
|
|
Menu menu;
|
|
|
|
Calibrator calibrator;
|
|
|
|
ClickGetter clickGetter;
|
|
|
|
|
|
|
|
//Pen
|
|
|
|
int penColor = color(200);
|
|
|
|
int penWidth = 15;
|
|
|
|
int operationSpeed = 10; //speed for Shrink, Expand, etc.
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String args[]) {
|
|
|
|
PApplet.main("EuglenaApplet");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void settings() {
|
|
|
|
size(1920, 1200, P2D);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setup() {
|
|
|
|
clear();
|
|
|
|
smooth();
|
|
|
|
|
|
|
|
camera = new Camera(this, cameraMode);
|
|
|
|
ledControl = new LEDControl(this, whichArduino);
|
|
|
|
|
|
|
|
menu = new Menu(this);
|
|
|
|
|
|
|
|
// Start up projectorApplet window
|
|
|
|
// Do this last, in case ProjectorApplet wants to use the camera, arduino, etc.
|
|
|
|
projectorApplet = new ProjectorApplet(this);
|
|
|
|
String[] args = {"Euglena projector"};
|
|
|
|
PApplet.runSketch(args, projectorApplet);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void draw() {
|
|
|
|
menu.draw(this, ledControl);
|
|
|
|
|
|
|
|
//Update webcam and draw the updated image to the screen
|
|
|
|
camera.updateImage();
|
|
|
|
imageMode(PApplet.CORNER);
|
|
|
|
image(camera.getImage(), 0, 0, width - menu.width, height);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseClicked(){
|
|
|
|
// Ignore mouse clicks in menu area
|
|
|
|
if (mouseX > width - menu.width) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have a clickGetter, use that to handle the mouse click
|
|
|
|
if (clickGetter != null) {
|
|
|
|
boolean done = clickGetter.click(mouseX, mouseY);
|
|
|
|
if (done) {
|
|
|
|
clickGetter = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void keyPressed() {
|
|
|
|
ledControl.keyPressed(key);
|
|
|
|
if (key == CODED) {
|
|
|
|
projectorApplet.calibrator.buttonPressed(keyCode);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
switch(key) {
|
|
|
|
case ENTER:
|
|
|
|
//TODO: snapshot
|
|
|
|
//snapshot();
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
//TODO: record
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void keyReleased() {
|
|
|
|
ledControl.keyReleased(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void controlEvent(ControlEvent theEvent) {
|
|
|
|
menu.controlEvent(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawArrow(int cx, int cy, int len, float angle){
|
|
|
|
pushMatrix();
|
|
|
|
translate(cx, cy);
|
|
|
|
rotate(radians(angle));
|
|
|
|
line(0,0,len, 0);
|
|
|
|
line(len, 0, len - 8, -8);
|
|
|
|
line(len, 0, len - 8, 8);
|
|
|
|
popMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
if (projectorApplet.calibrator.active) {
|
|
|
|
projectorApplet.calibrator.deactivate();
|
|
|
|
} else {
|
|
|
|
projectorApplet.calibrator.deactivate();
|
|
|
|
ledControl.allOff();
|
|
|
|
|
|
|
|
projectorApplet.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|