Wrote some comments and added compile instructions to the readme
This commit is contained in:
parent
170a45751c
commit
7dad701fe0
9 changed files with 368 additions and 248 deletions
|
|
@ -3,14 +3,28 @@ import processing.video.*;
|
|||
import static processing.core.PApplet.*;
|
||||
|
||||
class Camera {
|
||||
/*
|
||||
Camera controller.
|
||||
This class is mostly a wrapper around processing.video.Capture.
|
||||
*/
|
||||
|
||||
// Camera from which we want to update
|
||||
Capture cam;
|
||||
|
||||
// The latest image we got from the camera
|
||||
PImage latestImage;
|
||||
|
||||
/*
|
||||
Set up a camera.
|
||||
*/
|
||||
Camera(PApplet applet, int cameraMode) {
|
||||
/*
|
||||
Initialize a camera.
|
||||
|
||||
If you don't know what to set cameraMode to, just set it to 0
|
||||
and then look at the output; this function prints out a list
|
||||
of [cameraMode "1920x1080 60fps"] lines which you can use
|
||||
to choose the mode you want.
|
||||
*/
|
||||
String[] cameras = Capture.list();
|
||||
|
||||
if (cameras.length == 0) {
|
||||
println("There are no cameras available for capture.");
|
||||
applet.exit();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@ import controlP5.ControlEvent;
|
|||
import processing.core.*;
|
||||
|
||||
public class EuglenaApplet extends PApplet {
|
||||
/*
|
||||
This is the main Processing applet.
|
||||
*/
|
||||
|
||||
final int cameraMode = 9;
|
||||
final int whichArduino = 0;
|
||||
|
||||
|
|
@ -32,12 +36,17 @@ public class EuglenaApplet extends PApplet {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
/*
|
||||
Applet initialization
|
||||
*/
|
||||
clear();
|
||||
smooth();
|
||||
|
||||
// Initialize hardware
|
||||
camera = new Camera(this, cameraMode);
|
||||
ledControl = new LEDControl(this, whichArduino);
|
||||
|
||||
// Initialize software components
|
||||
menu = new Menu(this);
|
||||
|
||||
// Start up projectorApplet window
|
||||
|
|
@ -49,13 +58,17 @@ public class EuglenaApplet extends PApplet {
|
|||
|
||||
@Override
|
||||
public void draw() {
|
||||
/*
|
||||
Draw loop
|
||||
*/
|
||||
|
||||
//Draw the menu
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -77,6 +90,9 @@ public class EuglenaApplet extends PApplet {
|
|||
|
||||
@Override
|
||||
public void keyPressed() {
|
||||
/*
|
||||
Key-down handler
|
||||
*/
|
||||
ledControl.keyPressed(key);
|
||||
if (key == CODED) {
|
||||
projectorApplet.calibrator.buttonPressed(keyCode);
|
||||
|
|
@ -96,14 +112,23 @@ public class EuglenaApplet extends PApplet {
|
|||
|
||||
@Override
|
||||
public void keyReleased() {
|
||||
/*
|
||||
Key-up handler
|
||||
*/
|
||||
ledControl.keyReleased(key);
|
||||
}
|
||||
|
||||
public void controlEvent(ControlEvent theEvent) {
|
||||
/*
|
||||
Pass menu events to the menu component
|
||||
*/
|
||||
menu.controlEvent(theEvent);
|
||||
}
|
||||
|
||||
void drawArrow(int cx, int cy, int len, float angle){
|
||||
/*
|
||||
Utility function for drawing an arrow
|
||||
*/
|
||||
pushMatrix();
|
||||
translate(cx, cy);
|
||||
rotate(radians(angle));
|
||||
|
|
@ -114,6 +139,9 @@ public class EuglenaApplet extends PApplet {
|
|||
}
|
||||
|
||||
void reset() {
|
||||
/*
|
||||
Reset the applet to a known state
|
||||
*/
|
||||
if (projectorApplet.calibrator.active) {
|
||||
projectorApplet.calibrator.deactivate();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,10 @@ class LEDControl {
|
|||
print("Using arduino ");
|
||||
println(arduinos[whichArduino]);
|
||||
|
||||
/*
|
||||
ARDUINO IS DISABLED
|
||||
(since I don't always have one to test with...)
|
||||
*/
|
||||
// this.arduino = new Arduino(applet, arduinos[whichArduino], comRate);
|
||||
//
|
||||
// for (Direction dir : Direction.values()) {
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class Line {
|
|||
p.noFill();
|
||||
|
||||
p.line(p.convertXCoord(x1), p.convertYCoord(y1),
|
||||
p.convertXCoord(x2), p.convertYCoord(y2));
|
||||
p.convertXCoord(x2), p.convertYCoord(y2));
|
||||
|
||||
p.strokeWeight(old_strokeWeight);
|
||||
p.stroke(old_strokeColor);
|
||||
|
|
|
|||
|
|
@ -2,16 +2,32 @@ import processing.core.PApplet;
|
|||
import java.util.ArrayList;
|
||||
|
||||
class ProjectorApplet extends PApplet {
|
||||
/*
|
||||
Secondary applet for controlling what gets displayed on
|
||||
the projector.
|
||||
|
||||
This window runs as a separate thread, so in order to draw
|
||||
things, you should create a ProjectorCommand and queue it
|
||||
up with projectorApplet.commandQueue.add(myCommand).
|
||||
*/
|
||||
|
||||
// Which screen should we display on?
|
||||
final int projectorScreenNumber = 2;
|
||||
|
||||
// Center coordinates of the screen
|
||||
final static int centerX = 860;
|
||||
final static int centerY = 540;
|
||||
|
||||
// Background color
|
||||
int bgColor = color(0, 0, 0);
|
||||
|
||||
// Pointer to the main applet
|
||||
EuglenaApplet parent;
|
||||
|
||||
// Calibration component
|
||||
Calibrator calibrator;
|
||||
|
||||
// Queue of commands to execute
|
||||
ArrayList<ProjectorCommand> commandQueue;
|
||||
|
||||
ProjectorApplet(EuglenaApplet parent) {
|
||||
|
|
@ -27,11 +43,21 @@ class ProjectorApplet extends PApplet {
|
|||
@Override
|
||||
public void setup() {
|
||||
clear();
|
||||
// smooth(); // Smooth might create artefacts when animating?
|
||||
// smooth(); // Smooth might create artifacts when animating?
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
/*
|
||||
Main draw loop for the projector window
|
||||
*/
|
||||
|
||||
/*
|
||||
Exectue commands from the commandQueue.
|
||||
If a command finished, mark it for removal.
|
||||
If we get a ProjectorCommandException, don't execute
|
||||
any further commands.
|
||||
*/
|
||||
ArrayList<Integer> entriesToRemove = new ArrayList<>();
|
||||
try {
|
||||
for (int i = 0; i < commandQueue.size(); i++) {
|
||||
|
|
@ -46,21 +72,27 @@ class ProjectorApplet extends PApplet {
|
|||
// Do nothing
|
||||
}
|
||||
|
||||
// Remove entries (have to do it in reverse order to preserve indices)
|
||||
// Remove finished commands (have to do it in reverse order to preserve indices)
|
||||
for (int i = entriesToRemove.size() - 1; i >= 0; i--) {
|
||||
commandQueue.remove(i);
|
||||
}
|
||||
|
||||
|
||||
// Let the calibration module draw anything it needs
|
||||
calibrator.draw(parent);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
/*
|
||||
Clear the commandQueue and the screen
|
||||
*/
|
||||
commandQueue.clear();
|
||||
this.clear();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
/*
|
||||
Clear the screen
|
||||
*/
|
||||
fill(bgColor);
|
||||
noStroke();
|
||||
rectMode(CORNER);
|
||||
|
|
@ -79,6 +111,11 @@ class ProjectorApplet extends PApplet {
|
|||
return bgColor;
|
||||
}
|
||||
|
||||
/*
|
||||
Functions for converting coordinates and distances from
|
||||
main-window to projector-window coordinates
|
||||
*/
|
||||
|
||||
public float convertXCoord(float x) {
|
||||
return (x / calibrator.magx + width * calibrator.offsetx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
*
|
||||
/*
|
||||
* Currently unused?
|
||||
*/
|
||||
public class Settings {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue