diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4b7d33b..3c2a55d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,16 @@ + + + + + + + + @@ -27,7 +35,7 @@ - + @@ -51,14 +59,9 @@ - - - - - - - - + + + @@ -66,42 +69,58 @@ - - + + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + - + - - + + - + + @@ -110,8 +129,8 @@ - - + + @@ -122,10 +141,11 @@ - - + + - + + @@ -137,6 +157,7 @@ @@ -156,23 +177,27 @@ - @@ -185,7 +210,7 @@ - + @@ -198,18 +223,11 @@ - - - - - - - - + - - + + @@ -225,6 +243,7 @@ + - - - + - + + - + - + + @@ -371,7 +495,6 @@ - @@ -414,17 +537,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + @@ -440,7 +636,6 @@ - @@ -459,81 +654,11 @@ - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -541,6 +666,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -561,7 +719,6 @@ - @@ -581,14 +738,6 @@ - - - - - - - - @@ -601,100 +750,107 @@ - - + - - - - - - - - - - + + - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - + + - - + - - + + + + + + + + + + - + + + + + + + + + + + + + + + + + + diff --git a/src/Calibrator.java b/src/Calibrator.java index 4d90895..7f08dcd 100644 --- a/src/Calibrator.java +++ b/src/Calibrator.java @@ -2,6 +2,8 @@ doodle button is pressed */ import processing.core.*; +import static processing.core.PApplet.*; + class Calibrator { @@ -52,16 +54,16 @@ class Calibrator { // Calibration of projectorApplet field of view switch(keyCode) { - case PApplet.UP: + case UP: offsety = offsety - .001f; //Moves projections up in app view break; - case PApplet.DOWN: + case DOWN: offsety = offsety + .001f; //Moves projections down break; - case PApplet.LEFT: + case LEFT: offsetx = offsetx - .001f; // Moves projections left break; - case PApplet.RIGHT: + case RIGHT: offsetx = offsetx + .001f; // Moves projections right break; case 36: @@ -76,9 +78,9 @@ class Calibrator { case 34: magy = magy - .05f; // PAGE DOWN button increases height of projections break; - case PApplet.SHIFT: - PApplet.println("x-offset: " + offsetx + " | y-offset: " + offsety); - PApplet.println("x-magnification: " + magx + " | y-magnification: " + magy); + case SHIFT: + println("x-offset: " + offsetx + " | y-offset: " + offsety); + println("x-magnification: " + magx + " | y-magnification: " + magy); default: break; } diff --git a/src/Camera.java b/src/Camera.java index c3dfbd0..e955524 100644 --- a/src/Camera.java +++ b/src/Camera.java @@ -1,6 +1,6 @@ import processing.core.*; import processing.video.*; - +import static processing.core.PApplet.*; class Camera { Capture cam; @@ -12,19 +12,19 @@ class Camera { Camera(PApplet applet, int cameraMode) { String[] cameras = Capture.list(); if (cameras.length == 0) { - PApplet.println("There are no cameras available for capture."); + println("There are no cameras available for capture."); applet.exit(); } else { - PApplet.println("Available cameras:"); + println("Available cameras:"); for(int i = 0; i < cameras.length; i++) { - PApplet.println(i, cameras[i]); + println(i, cameras[i]); } - PApplet.print("Using camera mode "); - PApplet.println(cameras[cameraMode]); + print("Using camera mode "); + println(cameras[cameraMode]); this.cam = new Capture(applet, cameras[cameraMode]); this.cam.start(); - this.updateImage(); + latestImage = cam; //initialize unconditionally } } diff --git a/src/EllipseClass.java b/src/Ellipse.java similarity index 50% rename from src/EllipseClass.java rename to src/Ellipse.java index 7191a86..b9cf4cd 100644 --- a/src/EllipseClass.java +++ b/src/Ellipse.java @@ -21,16 +21,16 @@ import processing.core.*; // // void mouseClicked(ProjectorApplet p, float x, float y){ // if (!centerpointcomplete){ -// ellipseinprogress.centerx = x; -// ellipseinprogress.centery = y; +// ellipseinprogress.centerX = x; +// ellipseinprogress.centerY = y; // centerpointcomplete = true; // // } else if (!widthcomplete) { -// ellipseinprogress.width = PApplet.abs(ellipseinprogress.centerx - x) * 2; +// ellipseinprogress.width = PApplet.abs(ellipseinprogress.centerX - x) * 2; // widthcomplete = true; // // } else { -// ellipseinprogress.height = PApplet.abs(ellipseinprogress.centery - y) * 2; +// ellipseinprogress.height = PApplet.abs(ellipseinprogress.centerY - y) * 2; // ellipseinprogress.visible = true; // //ellipses.add(ellipseinprogress); // @@ -42,13 +42,13 @@ import processing.core.*; class Ellipse { - float centerx, centery, width, height; + float centerX, centerY, width, height; int red, green, blue, brushSize; boolean visible; - Ellipse(float centerx, float centery, float width, float height, int rVal, int gVal, int bVal, int penWidth) { - this.centerx = centerx; - this.centery = centery; + Ellipse(float centerX, float centerY, float width, float height, int rVal, int gVal, int bVal, int penWidth) { + this.centerX = centerX; + this.centerY = centerY; this.width = width; this.height = height; this.red = rVal; @@ -58,40 +58,24 @@ class Ellipse { this.visible = true; } - void draw(ProjectorApplet p) { + void draw(ProjectorApplet projector) { if (visible) { - float old_strokeWeight = p.g.strokeWeight; - int old_strokeColor = p.g.strokeColor; + projector.commandQueue.add( + (ProjectorApplet p) -> { + float old_strokeWeight = p.g.strokeWeight; + int old_strokeColor = p.g.strokeColor; - p.ellipseMode(PApplet.CENTER); - p.strokeWeight(brushSize); - p.stroke(p.color(red, green, blue)); - p.noFill(); + p.ellipseMode(PApplet.CENTER); + p.strokeWeight(brushSize); + p.stroke(p.color(red, green, blue)); + p.noFill(); - p.ellipse(p.convertXCoord(centerx), p.convertYCoord(centery), - p.convertXDistance(width), p.convertYDistance(height)); - p.strokeWeight(old_strokeWeight); - p.stroke(old_strokeColor); - - /* - print(rVal); - print(","); - print(gVal); - print(","); - print(bVal); - print("\n"); - */ - - /* - print(convertXCoord(centerx)); - print("\n"); - print(convertYCoord(centery)); - print("\n"); - print(convertXDistance(width)); - print("\n"); - print(convertYDistance(height)); - print("\n"); - */ + p.ellipse(p.convertXCoord(centerX), p.convertYCoord(centerY), + p.convertXDistance(width), p.convertYDistance(height)); + p.strokeWeight(old_strokeWeight); + p.stroke(old_strokeColor); + return true; + }); } } } diff --git a/src/EuglenaApplet.java b/src/EuglenaApplet.java index 2205dd2..957d9a0 100644 --- a/src/EuglenaApplet.java +++ b/src/EuglenaApplet.java @@ -1,7 +1,7 @@ import processing.core.*; public class EuglenaApplet extends PApplet { - final int cameraMode = 77; + final int cameraMode = 9; final int whichArduino = 0; // Hardware @@ -13,6 +13,8 @@ public class EuglenaApplet extends PApplet { Menu menu; Calibrator calibrator; + boolean tester; + public static void main(String args[]) { PApplet.main("EuglenaApplet"); } @@ -37,6 +39,7 @@ public class EuglenaApplet extends PApplet { projectorApplet = new ProjectorApplet(this); String[] args = {"Euglena projector"}; PApplet.runSketch(args, projectorApplet); + tester = false; } @Override @@ -48,6 +51,10 @@ public class EuglenaApplet extends PApplet { imageMode(PApplet.CORNER); image(camera.getImage(), 0, 0, width - menu.width, height); + if (!tester) { + new Ellipse(0f, 0f, 1000f, 1000f, 250, 250, 250, 8).draw(this.projectorApplet); + } + } diff --git a/src/LEDControl.java b/src/LEDControl.java index ae33ca7..d318434 100644 --- a/src/LEDControl.java +++ b/src/LEDControl.java @@ -1,4 +1,5 @@ import processing.core.*; +import static processing.core.PApplet.*; import cc.arduino.*; class LEDControl { @@ -11,15 +12,15 @@ class LEDControl { // Arduino - initialize correct arduino String[] arduinos = Arduino.list(); if (arduinos.length == 0) { - PApplet.println("There are no arduinos available for use."); + println("There are no arduinos available for use."); applet.exit(); } else { - PApplet.println("Available arduinos:"); + println("Available arduinos:"); for( String ard : arduinos) { - PApplet.println(ard); + println(ard); } - PApplet.print("Using arduino "); - PApplet.println(arduinos[whichArduino]); + print("Using arduino "); + println(arduinos[whichArduino]); // this.arduino = new Arduino(applet, arduinos[whichArduino], comRate); // diff --git a/src/Menu.java b/src/Menu.java index e577e0a..ddb0ad5 100644 --- a/src/Menu.java +++ b/src/Menu.java @@ -1,7 +1,4 @@ import processing.core.*; -import org.firmata.*; -import gab.opencv.*; -import cc.arduino.*; import controlP5.*; class Menu { diff --git a/src/ProjectorApplet.java b/src/ProjectorApplet.java index d5f5535..0397ece 100644 --- a/src/ProjectorApplet.java +++ b/src/ProjectorApplet.java @@ -1,5 +1,7 @@ import processing.core.PApplet; +import java.util.ArrayDeque; +import java.util.function.*; class ProjectorApplet extends PApplet { final int projectorScreenNumber = 2; @@ -10,9 +12,12 @@ class ProjectorApplet extends PApplet { EuglenaApplet parent; Calibrator calibrator; + ArrayDeque commandQueue; + ProjectorApplet(EuglenaApplet parent) { this.parent = parent; calibrator = new Calibrator(this); + commandQueue = new ArrayDeque<>(); } public void settings() { @@ -22,16 +27,25 @@ class ProjectorApplet extends PApplet { @Override public void setup() { clear(); - calibrator.activate(); +// calibrator.activate(); //for testing } @Override public void draw() { - background(50); - fill(255); - ellipse(mouseX, mouseY, 10, 10); +// background(50); +// fill(255); +// ellipse(mouseX, mouseY, 10, 10); calibrator.draw(parent); + + while (!commandQueue.isEmpty()) { + ProjectorCommand command = commandQueue.getFirst(); + if (command.run(this)) { + commandQueue.removeFirst(); + } else { + break; + } + } } public float convertXCoord(float x) { diff --git a/src/ProjectorCommand.java b/src/ProjectorCommand.java new file mode 100644 index 0000000..a90dd0d --- /dev/null +++ b/src/ProjectorCommand.java @@ -0,0 +1,3 @@ +public interface ProjectorCommand { + boolean run(ProjectorApplet p); +} diff --git a/src/shrinkingCircle.java b/src/shrinkingCircle.java index d32c3df..3c1974e 100644 --- a/src/shrinkingCircle.java +++ b/src/shrinkingCircle.java @@ -12,7 +12,7 @@ // SlowConcentrate(int centerX, int centerY){ // // this.centerX = centerX; -// this.centerY = centery; +// this.centerY = centerY; // this.speed = speedSet; // this.red = rVal; // this.green = gVal;