Merge branch 'master' of mpxd.net:jan/euglena
This commit is contained in:
commit
0c25bd0949
@ -1,3 +1,43 @@
|
||||
public interface ClickGetter {
|
||||
boolean click(int mouseX, int mouseY);
|
||||
}
|
||||
|
||||
|
||||
//public interface Shape {
|
||||
// public int numVertices();
|
||||
//}
|
||||
//
|
||||
//
|
||||
//class Circle2 implements Shape {
|
||||
// Circle2() {
|
||||
// blah;
|
||||
// }
|
||||
//
|
||||
// int numVertices() {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// void expand() {
|
||||
// blah2;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//class Square implements Shape {
|
||||
// int numVertices() {
|
||||
// return 4;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//Shape g = new Circle2();
|
||||
////g.expand(); // bad
|
||||
//println(g.numVertices()); //good
|
||||
//g = new Square();
|
||||
//println(g.numVertices());
|
||||
//
|
||||
//void printNumberOfVertices(Shape s) {
|
||||
// println(s.numVertices());
|
||||
//}
|
||||
//
|
||||
//printNumberOfVertices(new Circle2());
|
||||
//printNumberOfVertices(new Square());
|
||||
|
@ -32,7 +32,7 @@ class Ellipse {
|
||||
this.widthComplete = true;
|
||||
}
|
||||
|
||||
ProjectorCommand drawCommand() {
|
||||
ProjectorCommand makeProjectorCommand() {
|
||||
return (ProjectorApplet p) -> {
|
||||
if (!visible) {
|
||||
//done drawing already
|
||||
@ -49,13 +49,14 @@ class Ellipse {
|
||||
|
||||
p.ellipse(p.convertXCoord(centerX), p.convertYCoord(centerY),
|
||||
p.convertXDistance(width), p.convertYDistance(height));
|
||||
|
||||
p.strokeWeight(old_strokeWeight);
|
||||
p.stroke(old_strokeColor);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
ClickGetter makeClickGetter(ProjectorApplet p) {
|
||||
ClickGetter makeClickGetter(ProjectorApplet p){
|
||||
return (int x, int y) -> {
|
||||
if (!centerPointComplete){
|
||||
centerX = x;
|
||||
@ -72,7 +73,7 @@ class Ellipse {
|
||||
height = abs(centerY - y) * 2;
|
||||
visible = true;
|
||||
|
||||
p.commandQueue.add(drawCommand());
|
||||
p.commandQueue.add(makeProjectorCommand());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -18,6 +18,7 @@ public class EuglenaApplet extends PApplet {
|
||||
//Pen
|
||||
int penColor = color(200);
|
||||
int penWidth = 15;
|
||||
int operationSpeed = 10; //speed for Shrink, Expand, etc.
|
||||
|
||||
|
||||
public static void main(String args[]) {
|
||||
@ -60,8 +61,15 @@ public class EuglenaApplet extends PApplet {
|
||||
|
||||
@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) {
|
||||
if (clickGetter.click(mouseX, mouseY)) {
|
||||
boolean done = clickGetter.click(mouseX, mouseY);
|
||||
if (done) {
|
||||
clickGetter = null;
|
||||
}
|
||||
}
|
||||
@ -69,17 +77,12 @@ public class EuglenaApplet extends PApplet {
|
||||
|
||||
@Override
|
||||
public void keyPressed() {
|
||||
ledControl.keyPressed(key);
|
||||
if (key == CODED) {
|
||||
projectorApplet.calibrator.buttonPressed(keyCode);
|
||||
|
||||
} else {
|
||||
switch(key) {
|
||||
case 'd':
|
||||
case 'w':
|
||||
case 'a':
|
||||
case 's':
|
||||
ledControl.keyPressed(key);
|
||||
break;
|
||||
case ENTER:
|
||||
//TODO: snapshot
|
||||
//snapshot();
|
||||
@ -93,14 +96,7 @@ public class EuglenaApplet extends PApplet {
|
||||
|
||||
@Override
|
||||
public void keyReleased() {
|
||||
switch(key) {
|
||||
case 'd':
|
||||
case 'w':
|
||||
case 'a':
|
||||
case 's':
|
||||
ledControl.keyReleased(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void controlEvent(ControlEvent theEvent) {
|
||||
@ -124,18 +120,7 @@ public class EuglenaApplet extends PApplet {
|
||||
projectorApplet.calibrator.deactivate();
|
||||
ledControl.allOff();
|
||||
|
||||
projectorApplet.clear();
|
||||
|
||||
// lines.clear();
|
||||
// ellipses.clear();
|
||||
// rectangles.clear();
|
||||
// triangles.clear();
|
||||
|
||||
// shrinkwindows.clear();
|
||||
// expandwindows.clear();
|
||||
// translatewindows.clear();
|
||||
// rotatewindows.clear();
|
||||
|
||||
projectorApplet.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
99
src/Expand.java
Normal file
99
src/Expand.java
Normal file
@ -0,0 +1,99 @@
|
||||
import processing.core.*;
|
||||
import static processing.core.PApplet.*;
|
||||
|
||||
|
||||
public class Expand {
|
||||
float corner1x, corner1y, corner2x, corner2y, speed;
|
||||
int timeElapsed, millisInit;
|
||||
PImage expandRegion = null;
|
||||
|
||||
private boolean corner1complete;
|
||||
|
||||
Expand(float speed) {
|
||||
this.speed = speed;
|
||||
this.corner1complete = false;
|
||||
}
|
||||
|
||||
|
||||
Expand(float corner1x, float corner1y, float corner2x, float corner2y, float speed) {
|
||||
this.corner1x = corner1x;
|
||||
this.corner1y = corner1y;
|
||||
this.corner2x = corner2x;
|
||||
this.corner2y = corner2y;
|
||||
this.speed = speed;
|
||||
|
||||
this.corner1complete = true;
|
||||
}
|
||||
|
||||
float aspectRatio() {
|
||||
return abs((corner2x - corner1x) / (corner2y - corner1y));
|
||||
}
|
||||
|
||||
float centerx() {
|
||||
return (corner1x + corner2x) / 2;
|
||||
}
|
||||
|
||||
float centery() {
|
||||
return (corner1y + corner2y) / 2;
|
||||
}
|
||||
|
||||
void saveExpandRegion(ProjectorApplet p) {
|
||||
this.expandRegion = p.get(
|
||||
(int) p.convertXCoord(corner1x),
|
||||
(int) p.convertYCoord(corner1y),
|
||||
(int) abs(p.convertXDistance(corner2x - corner1x)),
|
||||
(int) abs(p.convertYDistance(corner2y - corner1y)));
|
||||
}
|
||||
|
||||
|
||||
ProjectorCommand makeProjectorCommand() {
|
||||
return (ProjectorApplet p) -> {
|
||||
if (expandRegion == null) {
|
||||
millisInit = p.millis();
|
||||
saveExpandRegion(p);
|
||||
}
|
||||
|
||||
timeElapsed = p.millis() - millisInit;
|
||||
|
||||
float spaceElapsed = speed * (timeElapsed / 1000f);
|
||||
|
||||
if (p.convertYDistance(corner2y - corner1y) + spaceElapsed >= p.convertYDistance(p.height)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
p.noFill();
|
||||
p.noStroke();
|
||||
p.rectMode(CORNER);
|
||||
p.rect(p.convertXCoord(corner1x), p.convertYCoord(corner1y),
|
||||
p.convertXDistance(corner2x - corner1x), p.convertYDistance(corner2y - corner1y));
|
||||
|
||||
p.imageMode(CENTER);
|
||||
p.image(expandRegion,
|
||||
p.convertXCoord(this.centerx()),
|
||||
p.convertYCoord(this.centery()),
|
||||
p.convertXDistance(corner2x - corner1x) + spaceElapsed * aspectRatio(),
|
||||
p.convertYDistance(corner2y - corner1y) + spaceElapsed);
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
ClickGetter makeClickGetter(ProjectorApplet p) {
|
||||
return (int x, int y) -> {
|
||||
if (!corner1complete) {
|
||||
corner1x = x;
|
||||
corner1y = y;
|
||||
corner1complete = true;
|
||||
return false;
|
||||
|
||||
} else {
|
||||
corner2x = x;
|
||||
corner2y = y;
|
||||
|
||||
p.commandQueue.add(makeProjectorCommand());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
class Expand {
|
||||
ExpandWindow expandinprogress;
|
||||
|
||||
boolean corner1complete;
|
||||
|
||||
void reset() {
|
||||
expandinprogress = new ExpandWindow(-1,-1,0,0,0);
|
||||
corner1complete = false;
|
||||
}
|
||||
|
||||
Expand(){
|
||||
corner1complete = false;
|
||||
}
|
||||
|
||||
void mouseClicked(float x, float y){
|
||||
if (!corner1complete){
|
||||
expandinprogress.corner1x = x;
|
||||
expandinprogress.corner1y = y;
|
||||
corner1complete = true;
|
||||
} else {
|
||||
expandinprogress.corner2x = x;
|
||||
expandinprogress.corner2y = y;
|
||||
expandinprogress.speed = speed;
|
||||
expandinprogress.millisInit = millis();
|
||||
expandinprogress.saveExpandRegion();
|
||||
expandwindows.add(expandinprogress);
|
||||
this.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ExpandWindow {
|
||||
float corner1x, corner1y, corner2x, corner2y, speed;
|
||||
int timeElapsed, millisInit;
|
||||
PImage expandRegion;
|
||||
|
||||
ExpandWindow(float corner1x, float corner1y, float corner2x, float corner2y, float speed) {
|
||||
this.corner1x = corner1x;
|
||||
this.corner1y = corner1y;
|
||||
this.corner2x = corner2x;
|
||||
this.corner2y = corner2y;
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
float aspectRatio() {
|
||||
return abs((corner2x - corner1x) / (corner2y - corner1y));
|
||||
}
|
||||
|
||||
float centerx() {
|
||||
return (corner1x + corner2x) / 2;
|
||||
}
|
||||
|
||||
float centery() {
|
||||
return (corner1y + corner2y) / 2;
|
||||
}
|
||||
|
||||
void saveExpandRegion() {
|
||||
this.expandRegion = get(int(convertXCoord(corner1x)), int(convertYCoord(corner1y)),
|
||||
int(convertXDistance(corner2x - corner1x)),int(convertYDistance(corner2y - corner1y)));
|
||||
}
|
||||
|
||||
void draw() {
|
||||
|
||||
timeElapsed = millis() - millisInit;
|
||||
|
||||
if (convertYDistance(corner2y - corner1y) + speed * (timeElapsed / 1000) < convertYDistance(screenHeight)) {
|
||||
|
||||
noFill();
|
||||
noStroke();
|
||||
rectMode(CORNER);
|
||||
rect(convertXCoord(corner1x), convertYCoord(corner1y),
|
||||
convertXDistance(corner2x - corner1x), convertYDistance(corner2y - corner1y));
|
||||
|
||||
|
||||
imageMode(CENTER);
|
||||
image(expandRegion, convertXCoord(this.centerx()), convertYCoord(this.centery()),
|
||||
convertXDistance(corner2x - corner1x) + speed * this.aspectRatio() * (timeElapsed / 1000),
|
||||
convertYDistance(corner2y - corner1y) + speed * (timeElapsed / 1000));
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -30,7 +30,7 @@ class Line {
|
||||
}
|
||||
|
||||
|
||||
ProjectorCommand drawCommand() {
|
||||
ProjectorCommand makeProjectorCommand() {
|
||||
return (ProjectorApplet p) -> {
|
||||
if (!visible) {
|
||||
//done drawing already
|
||||
@ -66,7 +66,7 @@ class Line {
|
||||
y2 = y;
|
||||
visible = true;
|
||||
|
||||
p.commandQueue.add(drawCommand());
|
||||
p.commandQueue.add(makeProjectorCommand());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -189,9 +189,7 @@ class Menu {
|
||||
}
|
||||
|
||||
void controlEvent(ControlEvent theEvent) {
|
||||
println(theEvent);
|
||||
println(theEvent.getName());
|
||||
println(theEvent.getLabel());
|
||||
//println(theEvent);
|
||||
if (theEvent.isFrom(shapesList)) {
|
||||
switch((int) shapesList.getValue()) {
|
||||
case 0:
|
||||
@ -210,20 +208,20 @@ class Menu {
|
||||
} else if (theEvent.isFrom(animateList)){
|
||||
switch((int) animateList.getValue()) {
|
||||
case 0:
|
||||
// shrink.reset();
|
||||
// drawtype = 's';
|
||||
parent.clickGetter = new Shrink(parent.operationSpeed)
|
||||
.makeClickGetter(parent.projectorApplet);
|
||||
break;
|
||||
case 1:
|
||||
// expand.reset();
|
||||
// drawtype = 'x';
|
||||
parent.clickGetter = new Expand(parent.operationSpeed)
|
||||
.makeClickGetter(parent.projectorApplet);
|
||||
break;
|
||||
case 2:
|
||||
// translate.reset();
|
||||
// drawtype = 'm';
|
||||
parent.clickGetter = new Translate(parent.operationSpeed)
|
||||
.makeClickGetter(parent.projectorApplet);
|
||||
break;
|
||||
case 3:
|
||||
// rotate.reset();
|
||||
// drawtype = 'c';
|
||||
parent.clickGetter = new Rotate(parent.operationSpeed)
|
||||
.makeClickGetter(parent.projectorApplet);
|
||||
break;
|
||||
}
|
||||
} else if (theEvent.isFrom(presetsList)){
|
||||
@ -231,16 +229,33 @@ class Menu {
|
||||
} else {
|
||||
switch (theEvent.getLabel()) {
|
||||
case "Commit":
|
||||
try {
|
||||
int rVal = Integer.parseInt(redField.getText());
|
||||
int gVal = Integer.parseInt(greenField.getText());
|
||||
int bVal = Integer.parseInt(blueField.getText());
|
||||
parent.penColor = parent.color(rVal, gVal, bVal);
|
||||
} catch (NumberFormatException e) {
|
||||
println("Ignored non-numeric color.");
|
||||
}
|
||||
|
||||
try {
|
||||
parent.penWidth = Integer.parseInt(penwidthField.getText());
|
||||
} catch (NumberFormatException e) {
|
||||
println("Ignored bad pen width");
|
||||
}
|
||||
|
||||
try {
|
||||
parent.projectorApplet.setBgColor(Integer.parseInt(backgroundField.getText()));
|
||||
} catch (NumberFormatException e) {
|
||||
println("Ignored bad background color.");
|
||||
}
|
||||
// parent.lagTime = Integer.parseInt(lagField.getText());
|
||||
// parent.totalTime = Integer.parseInt(totaltimeField.getText());
|
||||
// parent.speed = Integer.parseInt(speedField.getText());
|
||||
try {
|
||||
parent.operationSpeed = Integer.parseInt(speedField.getText());
|
||||
} catch (NumberFormatException e) {
|
||||
println("Ignored bad background color.");
|
||||
}
|
||||
break;
|
||||
|
||||
case "Reset":
|
||||
|
@ -1,6 +1,5 @@
|
||||
import processing.core.PApplet;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
|
||||
class ProjectorApplet extends PApplet {
|
||||
final int projectorScreenNumber = 2;
|
||||
@ -13,12 +12,12 @@ class ProjectorApplet extends PApplet {
|
||||
EuglenaApplet parent;
|
||||
Calibrator calibrator;
|
||||
|
||||
ArrayDeque<ProjectorCommand> commandQueue;
|
||||
ArrayList<ProjectorCommand> commandQueue;
|
||||
|
||||
ProjectorApplet(EuglenaApplet parent) {
|
||||
this.parent = parent;
|
||||
calibrator = new Calibrator(this);
|
||||
commandQueue = new ArrayDeque<>();
|
||||
commandQueue = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void settings() {
|
||||
@ -28,22 +27,37 @@ class ProjectorApplet extends PApplet {
|
||||
@Override
|
||||
public void setup() {
|
||||
clear();
|
||||
smooth();
|
||||
// calibrator.activate(); //for testing
|
||||
// smooth(); // Smooth might create artefacts when animating?
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
calibrator.draw(parent);
|
||||
ArrayList<Integer> entriesToRemove = new ArrayList<>();
|
||||
try {
|
||||
for (int i = 0; i < commandQueue.size(); i++) {
|
||||
|
||||
while (!commandQueue.isEmpty()) {
|
||||
ProjectorCommand command = commandQueue.getFirst();
|
||||
if (command.run(this)) {
|
||||
commandQueue.removeFirst();
|
||||
} else {
|
||||
break;
|
||||
boolean done = commandQueue.get(i).run(this);
|
||||
if (done) {
|
||||
entriesToRemove.add(i);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (ProjectorCommandException e) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
// Remove entries (have to do it in reverse order to preserve indices)
|
||||
for (int i = entriesToRemove.size() - 1; i >= 0; i--) {
|
||||
commandQueue.remove(i);
|
||||
}
|
||||
|
||||
|
||||
calibrator.draw(parent);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
commandQueue.clear();
|
||||
this.clear();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
|
@ -1,3 +1,3 @@
|
||||
public interface ProjectorCommand {
|
||||
boolean run(ProjectorApplet p);
|
||||
boolean run(ProjectorApplet p) throws ProjectorCommandException;
|
||||
}
|
||||
|
5
src/ProjectorCommandException.java
Normal file
5
src/ProjectorCommandException.java
Normal file
@ -0,0 +1,5 @@
|
||||
class ProjectorCommandException extends Exception {
|
||||
ProjectorCommandException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -30,7 +30,7 @@ class Rectangle {
|
||||
this.corner1complete = true;
|
||||
}
|
||||
|
||||
ProjectorCommand drawCommand() {
|
||||
ProjectorCommand makeProjectorCommand() {
|
||||
return (ProjectorApplet p) -> {
|
||||
if (!visible) {
|
||||
//done drawing already
|
||||
@ -61,12 +61,13 @@ class Rectangle {
|
||||
corner1y = y;
|
||||
corner1complete = true;
|
||||
return false;
|
||||
|
||||
} else {
|
||||
corner2x = x;
|
||||
corner2y = y;
|
||||
visible = true;
|
||||
|
||||
p.commandQueue.add(drawCommand());
|
||||
p.commandQueue.add(makeProjectorCommand());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
79
src/Rotate.java
Normal file
79
src/Rotate.java
Normal file
@ -0,0 +1,79 @@
|
||||
import processing.core.*;
|
||||
import static processing.core.PApplet.*;
|
||||
|
||||
|
||||
public class Rotate {
|
||||
float centerx, centery, radius, speed;
|
||||
int timeElapsed, millisInit;
|
||||
PImage rotateRegion = null;
|
||||
|
||||
private boolean centercomplete;
|
||||
|
||||
Rotate(float speed) {
|
||||
this.speed = speed;
|
||||
this.centercomplete = false;
|
||||
}
|
||||
|
||||
Rotate(float centerx, float centery, float radius, float speed) {
|
||||
this.centerx = centerx;
|
||||
this.centery = centery;
|
||||
this.radius = radius;
|
||||
this.speed = speed;
|
||||
|
||||
this.centercomplete = true;
|
||||
}
|
||||
|
||||
void saveRotateRegion(ProjectorApplet p) {
|
||||
this.rotateRegion = p.get(
|
||||
(int) p.convertXCoord(centerx - radius),
|
||||
(int) p.convertYCoord(centery - radius),
|
||||
(int) p.convertXDistance(2*radius),
|
||||
(int) p.convertYDistance(2*radius));
|
||||
}
|
||||
|
||||
ProjectorCommand makeProjectorCommand() {
|
||||
return (ProjectorApplet p) -> {
|
||||
if (rotateRegion == null) {
|
||||
millisInit = p.millis();
|
||||
saveRotateRegion(p);
|
||||
}
|
||||
|
||||
timeElapsed = p.millis() - millisInit;
|
||||
|
||||
p.noFill();
|
||||
p.noStroke();
|
||||
p.rectMode(CENTER);
|
||||
p.rect(p.convertXCoord(centerx), p.convertYCoord(centery),
|
||||
p.convertXDistance(radius), p.convertYDistance(radius));
|
||||
|
||||
p.pushMatrix();
|
||||
p.translate(p.convertXCoord(centerx), p.convertYCoord(centery));
|
||||
|
||||
p.rotate(radians(speed * timeElapsed/1000f));
|
||||
|
||||
p.imageMode(CENTER);
|
||||
p.image(rotateRegion, 0, 0, p.convertXDistance(2*radius), p.convertYDistance(2*radius));
|
||||
|
||||
p.popMatrix();
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
ClickGetter makeClickGetter(ProjectorApplet p){
|
||||
return (int x, int y) -> {
|
||||
if (!centercomplete){
|
||||
centerx = x;
|
||||
centery = y;
|
||||
centercomplete = true;
|
||||
return false;
|
||||
|
||||
} else {
|
||||
radius = sqrt(pow(x - centerx, 2) + pow(y - centery, 2));
|
||||
|
||||
p.commandQueue.add(makeProjectorCommand());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
class Rotate {
|
||||
RotateWindow rotateinprogress;
|
||||
|
||||
boolean centercomplete;
|
||||
|
||||
void reset() {
|
||||
rotateinprogress = new RotateWindow(-1,-1,0,0);
|
||||
centercomplete = false;
|
||||
}
|
||||
|
||||
Rotate(){
|
||||
centercomplete = false;
|
||||
}
|
||||
|
||||
void mouseClicked(float x, float y){
|
||||
if (!centercomplete){
|
||||
rotateinprogress.centerx = x;
|
||||
rotateinprogress.centery = y;
|
||||
centercomplete = true;
|
||||
} else {
|
||||
rotateinprogress.radius = sqrt(pow(x - rotateinprogress.centerx, 2) + pow(y - rotateinprogress.centery, 2));
|
||||
rotateinprogress.speed = speed;
|
||||
rotateinprogress.millisInit = millis();
|
||||
rotateinprogress.saveRotateRegion();
|
||||
rotatewindows.add(rotateinprogress);
|
||||
this.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RotateWindow {
|
||||
float centerx, centery, radius, speed;
|
||||
int timeElapsed, millisInit;
|
||||
PImage rotateRegion;
|
||||
|
||||
RotateWindow(float centerx, float centery, float radius, float speed) {
|
||||
this.centerx = centerx;
|
||||
this.centery = centery;
|
||||
this.radius = radius;
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
void saveRotateRegion() {
|
||||
this.rotateRegion = get(int(convertXCoord(centerx - radius)), int(convertYCoord(centery - radius)),
|
||||
int(convertXDistance(2*radius)),int(convertYDistance(2*radius)));
|
||||
}
|
||||
|
||||
void draw() {
|
||||
|
||||
timeElapsed = millis() - millisInit;
|
||||
|
||||
noFill();
|
||||
noStroke();
|
||||
rectMode(CENTER);
|
||||
rect(convertXCoord(centerx), convertYCoord(centery),
|
||||
convertXDistance(radius), convertYDistance(radius));
|
||||
|
||||
pushMatrix();
|
||||
translate(convertXCoord(centerx), convertYCoord(centery));
|
||||
|
||||
rotate(radians(speed*timeElapsed/1000));
|
||||
|
||||
imageMode(CENTER);
|
||||
image(rotateRegion, 0, 0, convertXDistance(2*radius), convertYDistance(2*radius));
|
||||
|
||||
popMatrix();
|
||||
}
|
||||
}
|
93
src/Shrink.java
Normal file
93
src/Shrink.java
Normal file
@ -0,0 +1,93 @@
|
||||
import processing.core.*;
|
||||
import static processing.core.PApplet.*;
|
||||
|
||||
|
||||
class Shrink {
|
||||
float corner1x, corner1y, corner2x, corner2y, speed;
|
||||
int timeElapsed, millisInit;
|
||||
PImage shrinkRegion = null;
|
||||
|
||||
private boolean corner1complete;
|
||||
|
||||
Shrink(float speed) {
|
||||
this.speed = speed;
|
||||
this.corner1complete = false;
|
||||
}
|
||||
|
||||
Shrink(float corner1x, float corner1y, float corner2x, float corner2y, float speed) {
|
||||
this.corner1x = corner1x;
|
||||
this.corner1y = corner1y;
|
||||
this.corner2x = corner2x;
|
||||
this.corner2y = corner2y;
|
||||
this.speed = speed;
|
||||
|
||||
this.corner1complete = true;
|
||||
}
|
||||
|
||||
float aspectRatio() {
|
||||
return abs((corner2x-corner1x)/(corner2y-corner1y));
|
||||
}
|
||||
|
||||
float centerx() {
|
||||
return (corner1x + corner2x) / 2;
|
||||
}
|
||||
|
||||
float centery() {
|
||||
return (corner1y + corner2y) / 2;
|
||||
}
|
||||
|
||||
void saveShrinkRegion(ProjectorApplet p) {
|
||||
this.shrinkRegion = p.get(
|
||||
(int) p.convertXCoord(corner1x),
|
||||
(int) p.convertYCoord(corner1y),
|
||||
(int) abs(p.convertXDistance(corner2x-corner1x)),
|
||||
(int) abs(p.convertYDistance(corner2y-corner1y)));
|
||||
}
|
||||
|
||||
ProjectorCommand makeProjectorCommand() {
|
||||
return (ProjectorApplet p) -> {
|
||||
if (shrinkRegion == null) {
|
||||
millisInit = p.millis();
|
||||
saveShrinkRegion(p);
|
||||
}
|
||||
|
||||
timeElapsed = p.millis() - millisInit;
|
||||
|
||||
if (p.convertXDistance(corner2x-corner1x) - speed * aspectRatio() * (timeElapsed/1000f) < 25) {
|
||||
return true;
|
||||
}
|
||||
|
||||
p.noFill();
|
||||
p.noStroke();
|
||||
p.rectMode(CORNER);
|
||||
p.rect(p.convertXCoord(corner1x), p.convertYCoord(corner1y),
|
||||
p.convertXDistance(corner2x - corner1x), p.convertYDistance(corner2y - corner1y));
|
||||
|
||||
p.imageMode(CENTER);
|
||||
p.image(shrinkRegion, p.convertXCoord(this.centerx()), p.convertYCoord(this.centery()),
|
||||
p.convertXDistance(corner2x - corner1x) - speed * aspectRatio() * (timeElapsed / 1000f),
|
||||
p.convertYDistance(corner2y - corner1y) - speed * (timeElapsed / 1000f));
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
ClickGetter makeClickGetter(ProjectorApplet p){
|
||||
return (int x, int y) -> {
|
||||
if (!corner1complete){
|
||||
corner1x = x;
|
||||
corner1y = y;
|
||||
corner1complete = true;
|
||||
return false;
|
||||
|
||||
} else {
|
||||
corner2x = x;
|
||||
corner2y = y;
|
||||
|
||||
p.commandQueue.add(makeProjectorCommand());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
class Shrink {
|
||||
ShrinkWindow shrinkinprogress;
|
||||
|
||||
boolean corner1complete;
|
||||
|
||||
void reset() {
|
||||
shrinkinprogress = new ShrinkWindow(-1,-1,0,0,0);
|
||||
corner1complete = false;
|
||||
}
|
||||
|
||||
Shrink(){
|
||||
corner1complete = false;
|
||||
}
|
||||
|
||||
void mouseClicked(float x, float y){
|
||||
if (!corner1complete){
|
||||
shrinkinprogress.corner1x = x;
|
||||
shrinkinprogress.corner1y = y;
|
||||
corner1complete = true;
|
||||
} else {
|
||||
shrinkinprogress.corner2x = x;
|
||||
shrinkinprogress.corner2y = y;
|
||||
shrinkinprogress.speed = speed;
|
||||
shrinkinprogress.millisInit = millis();
|
||||
shrinkinprogress.saveShrinkRegion();
|
||||
shrinkwindows.add(shrinkinprogress);
|
||||
this.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ShrinkWindow {
|
||||
float corner1x, corner1y, corner2x, corner2y, speed;
|
||||
int timeElapsed, millisInit;
|
||||
PImage shrinkRegion;
|
||||
|
||||
ShrinkWindow(float corner1x, float corner1y, float corner2x, float corner2y, float speed) {
|
||||
this.corner1x = corner1x;
|
||||
this.corner1y = corner1y;
|
||||
this.corner2x = corner2x;
|
||||
this.corner2y = corner2y;
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
float aspectRatio() {
|
||||
return abs((corner2x-corner1x)/(corner2y-corner1y));
|
||||
}
|
||||
|
||||
float centerx() {
|
||||
return (corner1x + corner2x) / 2;
|
||||
}
|
||||
|
||||
float centery() {
|
||||
return (corner1y + corner2y) / 2;
|
||||
}
|
||||
|
||||
void saveShrinkRegion() {
|
||||
this.shrinkRegion = get(int(convertXCoord(corner1x)), int(convertYCoord(corner1y)),
|
||||
abs(int(convertXDistance(corner2x-corner1x))), abs(int(convertYDistance(corner2y-corner1y))));
|
||||
}
|
||||
|
||||
void draw(){
|
||||
|
||||
timeElapsed = millis()-millisInit;
|
||||
if(convertXDistance(corner2x-corner1x) - speed * aspectRatio() * (timeElapsed/1000) > 25) {
|
||||
|
||||
noFill();
|
||||
noStroke();
|
||||
rectMode(CORNER);
|
||||
rect(convertXCoord(corner1x), convertYCoord(corner1y),
|
||||
convertXDistance(corner2x - corner1x), convertYDistance(corner2y - corner1y));
|
||||
|
||||
|
||||
imageMode(CENTER);
|
||||
image(shrinkRegion, convertXCoord(this.centerx()), convertYCoord(this.centery()),
|
||||
convertXDistance(corner2x - corner1x) - speed * aspectRatio() * (timeElapsed / 1000),
|
||||
convertYDistance(corner2y - corner1y) - speed * (timeElapsed / 1000));
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// print(convertXDistance(corner2x-corner1x) - speed * aspectRatio() * (timeElapsed/1000));
|
||||
// print("\n");
|
||||
// print(timeElapsed);
|
||||
// print("\n");
|
||||
// print(aspectRatio);
|
||||
// print("\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
114
src/Translate.java
Normal file
114
src/Translate.java
Normal file
@ -0,0 +1,114 @@
|
||||
import processing.core.*;
|
||||
import static processing.core.PApplet.*;
|
||||
|
||||
|
||||
public class Translate {
|
||||
float corner1x, corner1y, corner2x, corner2y, endpointx, endpointy, speed;
|
||||
int timeElapsed, millisInit;
|
||||
PImage translateRegion = null;
|
||||
|
||||
private boolean corner1complete, corner2complete;
|
||||
|
||||
Translate(float speed) {
|
||||
this.speed = speed;
|
||||
|
||||
this.corner1complete = false;
|
||||
this.corner2complete = false;
|
||||
}
|
||||
|
||||
Translate(float corner1x, float corner1y, float corner2x, float corner2y,
|
||||
float endpointx, float endpointy, float speed) {
|
||||
this.corner1x = corner1x;
|
||||
this.corner1y = corner1y;
|
||||
this.corner2x = corner2x;
|
||||
this.corner2y = corner2y;
|
||||
this.endpointx = endpointx;
|
||||
this.endpointy = endpointy;
|
||||
this.speed = speed;
|
||||
|
||||
this.corner1complete = true;
|
||||
this.corner2complete = true;
|
||||
}
|
||||
|
||||
|
||||
float centerx() {
|
||||
return (corner1x + corner2x) / 2;
|
||||
}
|
||||
|
||||
float centery() {
|
||||
return (corner1y + corner2y) / 2;
|
||||
}
|
||||
|
||||
float theta() {
|
||||
return (atan((endpointy-centery())/(endpointx-centerx())));
|
||||
}
|
||||
|
||||
void saveTranslateRegion(ProjectorApplet p) {
|
||||
this.translateRegion = p.get(
|
||||
(int) p.convertXCoord(corner1x),
|
||||
(int) p.convertYCoord(corner1y),
|
||||
(int) abs(p.convertXDistance(corner2x-corner1x)),
|
||||
(int) abs(p.convertYDistance(corner2y-corner1y)));
|
||||
}
|
||||
|
||||
|
||||
ProjectorCommand makeProjectorCommand() {
|
||||
return (ProjectorApplet p) -> {
|
||||
if (translateRegion == null) {
|
||||
millisInit = p.millis();
|
||||
saveTranslateRegion(p);
|
||||
}
|
||||
|
||||
timeElapsed = p.millis() - millisInit;
|
||||
|
||||
float spaceElapsed = timeElapsed * speed / 1000f;
|
||||
|
||||
if (spaceElapsed * cos(theta()) * p.calibrator.magx > endpointx - centerx()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
p.noFill();
|
||||
p.noStroke();
|
||||
p.rectMode(CORNERS);
|
||||
p.rect(p.convertXCoord(corner1x) + spaceElapsed * cos(theta()),
|
||||
p.convertYCoord(corner1y) + spaceElapsed * sin(theta()),
|
||||
p.convertXCoord(corner2x) + spaceElapsed * cos(theta()),
|
||||
p.convertYCoord(corner2y) + spaceElapsed * sin(theta()));
|
||||
|
||||
|
||||
p.imageMode(CENTER);
|
||||
p.image(translateRegion,
|
||||
p.convertXCoord(this.centerx()) + spaceElapsed * cos(theta()),
|
||||
p.convertYCoord(this.centery()) + spaceElapsed * sin(theta()),
|
||||
p.convertXDistance(corner2x - corner1x),
|
||||
p.convertYDistance(corner2y - corner1y));
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
ClickGetter makeClickGetter(ProjectorApplet p){
|
||||
return (int x, int y) -> {
|
||||
if (!corner1complete){
|
||||
corner1x = x;
|
||||
corner1y = y;
|
||||
corner1complete = true;
|
||||
return false;
|
||||
|
||||
} else if (!corner2complete) {
|
||||
corner2x = x;
|
||||
corner2y = y;
|
||||
corner2complete = true;
|
||||
return false;
|
||||
|
||||
} else{
|
||||
endpointx = x;
|
||||
endpointy = y;
|
||||
|
||||
p.commandQueue.add(makeProjectorCommand());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
class Translate {
|
||||
TranslateWindow translateWindowinprogress;
|
||||
|
||||
boolean corner1complete, corner2complete;
|
||||
|
||||
void reset() {
|
||||
translateWindowinprogress = new TranslateWindow(-1,-1,0,0,0,0,0);
|
||||
corner1complete = false;
|
||||
corner2complete = false;
|
||||
}
|
||||
|
||||
Translate(){
|
||||
corner1complete = false;
|
||||
corner2complete = false;
|
||||
}
|
||||
|
||||
void mouseClicked(float x, float y){
|
||||
if (!corner1complete){
|
||||
translateWindowinprogress.corner1x = x;
|
||||
translateWindowinprogress.corner1y = y;
|
||||
corner1complete = true;
|
||||
} else if (!corner2complete) {
|
||||
translateWindowinprogress.corner2x = x;
|
||||
translateWindowinprogress.corner2y = y;
|
||||
corner2complete = true;
|
||||
} else{
|
||||
translateWindowinprogress.endpointx = x;
|
||||
translateWindowinprogress.endpointy = y;
|
||||
translateWindowinprogress.speed = speed;
|
||||
translateWindowinprogress.millisInit = millis();
|
||||
translateWindowinprogress.saveTranslateRegion();
|
||||
translatewindows.add(translateWindowinprogress);
|
||||
this.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TranslateWindow {
|
||||
float corner1x, corner1y, corner2x, corner2y, endpointx, endpointy, speed;
|
||||
int timeElapsed, millisInit;
|
||||
PImage translateRegion;
|
||||
|
||||
TranslateWindow(float corner1x, float corner1y, float corner2x, float corner2y,
|
||||
float endpointx, float endpointy, float speed) {
|
||||
this.corner1x = corner1x;
|
||||
this.corner1y = corner1y;
|
||||
this.corner2x = corner2x;
|
||||
this.corner2y = corner2y;
|
||||
this.endpointx = endpointx;
|
||||
this.endpointy = endpointy;
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
|
||||
// float aspectRatio() {
|
||||
// return abs((corner2x - corner1x) / (corner2y - corner1y));
|
||||
// }
|
||||
|
||||
float centerx() {
|
||||
return (corner1x + corner2x) / 2;
|
||||
}
|
||||
|
||||
float centery() {
|
||||
return (corner1y + corner2y) / 2;
|
||||
}
|
||||
|
||||
float theta() {
|
||||
return (atan((endpointy-centery())/(endpointx-centerx())));
|
||||
}
|
||||
|
||||
void saveTranslateRegion() {
|
||||
this.translateRegion = get(int(convertXCoord(corner1x)), int(convertYCoord(corner1y)),
|
||||
int(abs(convertXDistance(corner2x - corner1x))),int(abs(convertYDistance(corner2y - corner1y))));
|
||||
}
|
||||
|
||||
void draw() {
|
||||
|
||||
timeElapsed = millis() - millisInit;
|
||||
|
||||
if (timeElapsed*speed/1000*cos(theta())*calibrator.magx <= endpointx - centerx()) {
|
||||
|
||||
noFill();
|
||||
noStroke();
|
||||
rectMode(CORNERS);
|
||||
rect(convertXCoord(corner1x) + timeElapsed*speed/1000*cos(theta()),
|
||||
convertYCoord(corner1y) + timeElapsed*speed/1000*sin(theta()),
|
||||
convertXCoord(corner2x) + timeElapsed*speed/1000*cos(theta()),
|
||||
convertYCoord(corner2y) + timeElapsed*speed/1000*sin(theta()));
|
||||
|
||||
|
||||
imageMode(CENTER);
|
||||
image(translateRegion, convertXCoord(this.centerx()) + timeElapsed*speed/1000*cos(theta()),
|
||||
convertYCoord(this.centery()) + timeElapsed*speed/1000*sin(theta()),
|
||||
convertXDistance(corner2x - corner1x), convertYDistance(corner2y - corner1y));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -35,7 +35,7 @@ class Triangle {
|
||||
this.point2complete = true;
|
||||
}
|
||||
|
||||
ProjectorCommand drawCommand() {
|
||||
ProjectorCommand makeProjectorCommand() {
|
||||
return (ProjectorApplet p) -> {
|
||||
if (!visible) {
|
||||
//done drawing already
|
||||
@ -78,7 +78,7 @@ class Triangle {
|
||||
point3y = y;
|
||||
visible = true;
|
||||
|
||||
p.commandQueue.add(drawCommand());
|
||||
p.commandQueue.add(makeProjectorCommand());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -1,3 +1,5 @@
|
||||
package oldfiles;
|
||||
|
||||
class EuglenaCounter {
|
||||
|
||||
int roiX, roiY, roiWidth, roiHeight, lastMillis, avgTime;
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
package oldfiles;/*
|
||||
Previously implemented programs which we need to redo using classes
|
||||
case 2 : // Starts clear program
|
||||
clearScreen();
|
@ -21,9 +21,6 @@ final int roiCornerX = 610;
|
||||
final int roiCornerY = 290;
|
||||
|
||||
|
||||
final int centerY = 540; // Center Y coordinate
|
||||
final int centerX = 860; // Center X coordinate
|
||||
|
||||
/* Global Variables */
|
||||
///////////////// Miscellaneaous Variables
|
||||
boolean load = false; // Boolean to determine if user wants to load previously saved led sequences or paint
|
||||
@ -75,11 +72,6 @@ boolean densityMeasured = false;
|
||||
FloatList fadeXCoord = new FloatList(); // Stores x-coordinate of each point
|
||||
FloatList fadeYCoord = new FloatList();
|
||||
|
||||
Shrink shrink = new Shrink();
|
||||
Expand expand = new Expand();
|
||||
Translate translate = new Translate();
|
||||
Rotate rotate = new Rotate();
|
||||
|
||||
|
||||
void setup() {
|
||||
count = 1;
|
||||
@ -102,23 +94,6 @@ void draw() {
|
||||
|
||||
recordTimelapse(lagTime, totalTime); //Note: the maximum fps is around 5
|
||||
|
||||
|
||||
for (int i=0; i < shrinkwindows.size(); i++) {
|
||||
shrinkwindows.get(i).draw();
|
||||
}
|
||||
|
||||
for (int i=0; i < expandwindows.size(); i++) {
|
||||
expandwindows.get(i).draw();
|
||||
}
|
||||
|
||||
for (int i=0; i < translatewindows.size(); i++) {
|
||||
translatewindows.get(i).draw();
|
||||
}
|
||||
|
||||
for (int i=0; i < rotatewindows.size(); i++) {
|
||||
rotatewindows.get(i).draw();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user