Browse Source

Merge branch 'master' of mpxd.net:jan/euglena

master
jan 5 years ago
parent
commit
0c25bd0949
  1. 40
      src/ClickGetter.java
  2. 7
      src/Ellipse.java
  3. 39
      src/EuglenaApplet.java
  4. 99
      src/Expand.java
  5. 84
      src/ExpandClass.java
  6. 4
      src/Line.java
  7. 53
      src/Menu.java
  8. 40
      src/ProjectorApplet.java
  9. 2
      src/ProjectorCommand.java
  10. 5
      src/ProjectorCommandException.java
  11. 5
      src/Rectangle.java
  12. 79
      src/Rotate.java
  13. 68
      src/RotateClass.java
  14. 93
      src/Shrink.java
  15. 93
      src/ShrinkClass.java
  16. 114
      src/Translate.java
  17. 99
      src/TranslateClass.java
  18. 4
      src/Triangle.java
  19. 2
      src/oldfiles/ObjectRecognition.java
  20. 2
      src/oldfiles/Presets.java
  21. 0
      src/oldfiles/angleGather.java
  22. 0
      src/oldfiles/angleMove.java
  23. 0
      src/oldfiles/circleArrayStim.java
  24. 0
      src/oldfiles/clearScreen.java
  25. 0
      src/oldfiles/colorScreen.java
  26. 0
      src/oldfiles/developer.java
  27. 25
      src/oldfiles/euglena_basic_stimuli.java
  28. 0
      src/oldfiles/gradientWindow.java
  29. 0
      src/oldfiles/heatup.java
  30. 0
      src/oldfiles/identifyEuglena.java
  31. 0
      src/oldfiles/lineRotate.java
  32. 0
      src/oldfiles/merge.java
  33. 0
      src/oldfiles/objDensity.java
  34. 0
      src/oldfiles/proto488flashraster.java
  35. 0
      src/oldfiles/protoClear.java
  36. 0
      src/oldfiles/protoGather.java
  37. 0
      src/oldfiles/randomLED.java
  38. 0
      src/oldfiles/recordTimelapse.java
  39. 0
      src/oldfiles/rectangularStim.java
  40. 0
      src/oldfiles/separate.java
  41. 0
      src/oldfiles/showCV.java
  42. 0
      src/oldfiles/shrinkingCircle.java
  43. 0
      src/oldfiles/shrinkingWindow.java
  44. 0
      src/oldfiles/sketch.properties
  45. 0
      src/oldfiles/snapshot.java
  46. 0
      src/oldfiles/squareCorridor.java
  47. 0
      src/oldfiles/testing.java
  48. 0
      src/oldfiles/translateCircle.java
  49. 0
      src/oldfiles/unidirectionStim.java
  50. 0
      src/oldfiles/window.java

40
src/ClickGetter.java

@ -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());

7
src/Ellipse.java

@ -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;
}
};

39
src/EuglenaApplet.java

@ -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;
}
ledControl.keyReleased(key);
}
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

@ -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;
}
};
}
}

84
src/ExpandClass.java

@ -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));
}
}
}

4
src/Line.java

@ -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;
}
};

53
src/Menu.java

@ -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":
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);
parent.penWidth = Integer.parseInt(penwidthField.getText());
parent.projectorApplet.setBgColor(Integer.parseInt(backgroundField.getText()));
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":

40
src/ProjectorApplet.java

@ -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++) {
boolean done = commandQueue.get(i).run(this);
if (done) {
entriesToRemove.add(i);
}
while (!commandQueue.isEmpty()) {
ProjectorCommand command = commandQueue.getFirst();
if (command.run(this)) {
commandQueue.removeFirst();
} else {
break;
}
} 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() {

2
src/ProjectorCommand.java

@ -1,3 +1,3 @@
public interface ProjectorCommand {
boolean run(ProjectorApplet p);
boolean run(ProjectorApplet p) throws ProjectorCommandException;
}

5
src/ProjectorCommandException.java

@ -0,0 +1,5 @@
class ProjectorCommandException extends Exception {
ProjectorCommandException(String message) {
super(message);
}
}

5
src/Rectangle.java

@ -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

@ -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;
}
};
}
}

68
src/RotateClass.java

@ -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

@ -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;
}
};
}
}

93
src/ShrinkClass.java

@ -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

@ -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;
}
};
}
}

99
src/TranslateClass.java

@ -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));
}
}
}

4
src/Triangle.java

@ -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;
}
};

2
src/ObjectRecognition.java → src/oldfiles/ObjectRecognition.java

@ -1,3 +1,5 @@
package oldfiles;
class EuglenaCounter {
int roiX, roiY, roiWidth, roiHeight, lastMillis, avgTime;

2
src/Presets.java → src/oldfiles/Presets.java

@ -1,4 +1,4 @@
/*
package oldfiles;/*
Previously implemented programs which we need to redo using classes
case 2 : // Starts clear program
clearScreen();

0
src/angleGather.java → src/oldfiles/angleGather.java

0
src/angleMove.java → src/oldfiles/angleMove.java

0
src/circleArrayStim.java → src/oldfiles/circleArrayStim.java

0
src/clearScreen.java → src/oldfiles/clearScreen.java

0
src/colorScreen.java → src/oldfiles/colorScreen.java

0
src/developer.java → src/oldfiles/developer.java

25
src/euglena_basic_stimuli.java → src/oldfiles/euglena_basic_stimuli.java

@ -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();
}
}

0
src/gradientWindow.java → src/oldfiles/gradientWindow.java

0
src/heatup.java → src/oldfiles/heatup.java

0
src/identifyEuglena.java → src/oldfiles/identifyEuglena.java

0
src/lineRotate.java → src/oldfiles/lineRotate.java

0
src/merge.java → src/oldfiles/merge.java

0
src/objDensity.java → src/oldfiles/objDensity.java

0
src/proto488flashraster.java → src/oldfiles/proto488flashraster.java

0
src/protoClear.java → src/oldfiles/protoClear.java

0
src/protoGather.java → src/oldfiles/protoGather.java

0
src/randomLED.java → src/oldfiles/randomLED.java

0
src/recordTimelapse.java → src/oldfiles/recordTimelapse.java

0
src/rectangularStim.java → src/oldfiles/rectangularStim.java

0
src/separate.java → src/oldfiles/separate.java

0
src/showCV.java → src/oldfiles/showCV.java

0
src/shrinkingCircle.java → src/oldfiles/shrinkingCircle.java

0
src/shrinkingWindow.java → src/oldfiles/shrinkingWindow.java

0
src/sketch.properties → src/oldfiles/sketch.properties

0
src/snapshot.java → src/oldfiles/snapshot.java

0
src/squareCorridor.java → src/oldfiles/squareCorridor.java

0
src/testing.java → src/oldfiles/testing.java

0
src/translateCircle.java → src/oldfiles/translateCircle.java

0
src/unidirectionStim.java → src/oldfiles/unidirectionStim.java

0
src/window.java → src/oldfiles/window.java

Loading…
Cancel
Save