euglena/src/ProjectorApplet.java

84 lines
1.8 KiB
Java
Raw Normal View History

2016-07-09 17:16:15 -07:00
import processing.core.PApplet;
2016-07-10 06:24:02 -07:00
import java.util.ArrayDeque;
2016-07-09 17:16:15 -07:00
class ProjectorApplet extends PApplet {
final int projectorScreenNumber = 2;
final static int centerX = 860;
final static int centerY = 540;
2016-07-10 09:03:16 -07:00
int bgColor = color(0, 0, 0);
2016-07-10 00:21:47 -07:00
EuglenaApplet parent;
Calibrator calibrator;
2016-07-10 06:24:02 -07:00
ArrayDeque<ProjectorCommand> commandQueue;
2016-07-10 00:21:47 -07:00
ProjectorApplet(EuglenaApplet parent) {
this.parent = parent;
calibrator = new Calibrator(this);
2016-07-10 06:24:02 -07:00
commandQueue = new ArrayDeque<>();
2016-07-10 00:21:47 -07:00
}
2016-07-09 17:16:15 -07:00
public void settings() {
fullScreen(P2D, this.projectorScreenNumber);
}
@Override
public void setup() {
clear();
2016-07-10 09:03:16 -07:00
smooth();
2016-07-10 06:24:02 -07:00
// calibrator.activate(); //for testing
2016-07-09 17:16:15 -07:00
}
@Override
public void draw() {
2016-07-10 00:21:47 -07:00
calibrator.draw(parent);
2016-07-10 06:24:02 -07:00
while (!commandQueue.isEmpty()) {
ProjectorCommand command = commandQueue.getFirst();
if (command.run(this)) {
commandQueue.removeFirst();
} else {
break;
}
}
2016-07-10 00:21:47 -07:00
}
2016-07-10 09:03:16 -07:00
public void clear() {
fill(bgColor);
noStroke();
rectMode(CORNER);
rect(0, 0, width * 4, height * 4);
}
public void setBgColor(int c) {
bgColor = c;
}
public void setBgColor(int r, int b, int g) {
bgColor = color(r, g, b);
}
public int getBgColor() {
return bgColor;
}
2016-07-10 00:21:47 -07:00
public float convertXCoord(float x) {
return (x / calibrator.magx + width * calibrator.offsetx);
}
public float convertYCoord(float y) {
return (y / calibrator.magy + height * calibrator.offsety);
}
public float convertXDistance(float dx) {
return (dx / calibrator.magx);
}
public float convertYDistance(float dy) {
return (dy / calibrator.magy);
2016-07-09 17:16:15 -07:00
}
}