euglena/src/EuglenaApplet.java

138 lines
3.2 KiB
Java
Raw Normal View History

import controlP5.ControlEvent;
2016-07-09 17:16:15 -07:00
import processing.core.*;
public class EuglenaApplet extends PApplet {
2016-07-10 06:24:02 -07:00
final int cameraMode = 9;
2016-07-09 17:16:15 -07:00
final int whichArduino = 0;
// Hardware
ProjectorApplet projectorApplet;
Camera camera;
LEDControl ledControl;
// Software components
Menu menu;
2016-07-10 00:21:47 -07:00
Calibrator calibrator;
2016-07-10 07:14:09 -07:00
ClickGetter clickGetter;
2016-07-09 17:16:15 -07:00
//Pen
int penColor = color(200);
int penWidth = 15;
2016-07-10 06:24:02 -07:00
2016-07-09 17:16:15 -07:00
public static void main(String args[]) {
PApplet.main("EuglenaApplet");
}
@Override
public void settings() {
2016-07-09 17:51:24 -07:00
size(1920, 1200, P2D);
2016-07-09 17:16:15 -07:00
}
@Override
public void setup() {
clear();
smooth();
camera = new Camera(this, cameraMode);
ledControl = new LEDControl(this, whichArduino);
menu = new Menu(this);
2016-07-09 17:51:24 -07:00
// Start up projectorApplet window
// Do this last, in case ProjectorApplet wants to use the camera, arduino, etc.
2016-07-10 00:21:47 -07:00
projectorApplet = new ProjectorApplet(this);
2016-07-09 17:51:24 -07:00
String[] args = {"Euglena projector"};
PApplet.runSketch(args, projectorApplet);
2016-07-09 17:16:15 -07:00
}
@Override
public void draw() {
2016-07-10 00:21:47 -07:00
menu.draw(this, ledControl);
//Update webcam and draw the updated image to the screen
2016-07-09 17:51:24 -07:00
camera.updateImage();
imageMode(PApplet.CORNER);
2016-07-10 00:21:47 -07:00
image(camera.getImage(), 0, 0, width - menu.width, height);
2016-07-09 17:16:15 -07:00
}
2016-07-10 07:14:09 -07:00
@Override
public void mouseClicked(){
2016-07-10 17:51:01 -07:00
// Ignore mouse clicks in menu area
if (mouseX > width - menu.width) {
return;
}
// If we have a clickGetter, use that to handle the mouse click
2016-07-10 07:14:09 -07:00
if (clickGetter != null) {
2016-07-10 17:51:01 -07:00
boolean done = clickGetter.click(mouseX, mouseY);
if (done) {
2016-07-10 07:14:09 -07:00
clickGetter = null;
}
}
}
@Override
public void keyPressed() {
2016-07-10 17:51:01 -07:00
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() {
2016-07-10 17:51:01 -07:00
ledControl.keyReleased(key);
}
public void controlEvent(ControlEvent theEvent) {
menu.controlEvent(theEvent);
}
2016-07-09 17:16:15 -07:00
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();
}
2016-07-10 09:03:16 -07:00
void reset() {
if (projectorApplet.calibrator.active) {
projectorApplet.calibrator.deactivate();
} else {
projectorApplet.calibrator.deactivate();
ledControl.allOff();
projectorApplet.clear();
// lines.clear();
// ellipses.clear();
// rectangles.clear();
// triangles.clear();
// shrinkwindows.clear();
// expandwindows.clear();
// translatewindows.clear();
// rotatewindows.clear();
}
}
2016-07-09 17:16:15 -07:00
}