diff --git a/magic_veneer_processing/magic_veneer_processing.pde b/magic_veneer_processing/magic_veneer_processing.pde index fbb85f0..7d82c7a 100644 --- a/magic_veneer_processing/magic_veneer_processing.pde +++ b/magic_veneer_processing/magic_veneer_processing.pde @@ -4,7 +4,9 @@ Serial arduinoPort; String receivedMessage; boolean cameIntoThreshhold = false; -int radius = 0; +float placementIndicatorOffsetX = 0; +int placementIndicatorAnimationCounter = 0; +String placementIndicatorAnimationDirection = "right"; void setup() { /* Set up screen */ @@ -17,7 +19,29 @@ void setup() { } void draw() { - println("Test"); + /* START - Create and animate placementIndicator */ + background(0); + placementIndicator(80, 8, placementIndicatorOffsetX); + + if (placementIndicatorAnimationCounter < 5) { + if (placementIndicatorAnimationDirection == "right" && placementIndicatorOffsetX < 30) { + placementIndicatorOffsetX += 2; + } else if (placementIndicatorAnimationDirection == "right" && placementIndicatorOffsetX <= 30) { + placementIndicatorAnimationDirection = "left"; + placementIndicatorOffsetX -= 2; + placementIndicatorAnimationCounter++; + } else if (placementIndicatorAnimationDirection == "left" && placementIndicatorOffsetX >= -30) { + placementIndicatorOffsetX -= 2; + } else if (placementIndicatorAnimationDirection == "left" && placementIndicatorOffsetX <= -30) { + placementIndicatorAnimationDirection = "right"; + placementIndicatorOffsetX += 2; + placementIndicatorAnimationCounter++; + } + } else { + placementIndicatorOffsetX = 0; + } + /* END - Create and animate placementIndicator */ + /* if ( arduinoPort.available() > 0) { String rec = arduinoPort.readStringUntil('\n'); if (rec != null) { @@ -28,9 +52,57 @@ void draw() { if (receivedMessage != null && receivedMessage.contains("isWithinThreshhold")) { cameIntoThreshhold = true; } - } - - circle(width / 2, height / 2, radius); - fill(0); - radius += 10; */ + }*/ } + +void placementIndicator(float polygonRadius, int npoints, float offsetX) { + float centerX = width / 2; + float centerY = height / 2; + + polygon(centerX + offsetX, centerY + polygonRadius * 2.75, polygonRadius * 0.8, npoints); + polygon(centerX + offsetX * 0.9, centerY + polygonRadius * 1.6, polygonRadius, npoints); + polygon(centerX + offsetX * 0.7, centerY, polygonRadius, npoints); + polygon(centerX + offsetX * 0.3, centerY - polygonRadius * 1.6, polygonRadius, npoints); + head(centerX, centerY, polygonRadius, 8); +} + +void polygon(float x, float y, float radius, int npoints) { + float angle = TWO_PI / npoints; + beginShape(); + for (float a = 0; a < TWO_PI; a += angle) { + float sx = x + cos(a) * radius; + float sy = y + sin(a) * radius; + vertex(sx, sy); + } + fill(255); + stroke(255); + endShape(CLOSE); +} + +void head(float x, float y, float polygonRadius, int npoints) { + polygon(x, y - polygonRadius * 2.75, polygonRadius * 0.8, npoints); + + PShape leftAntenna = antenna(2); + PShape rightAntenna = antenna(2); + + pushMatrix(); + leftAntenna.translate(x - 45, y - polygonRadius * 3.7); + leftAntenna.rotate(radians(350)); + shape(leftAntenna); + popMatrix(); + + pushMatrix(); + rightAntenna.translate(x + 35, y - polygonRadius * 3.7); + rightAntenna.rotate(radians(10)); + shape(rightAntenna); + popMatrix(); +} + +PShape antenna(float scale) { + PShape antenna = createShape(RECT, 0, 0, 5 * scale, 25 * scale); + antenna.setFill(color(255)); + antenna.setStroke(color(255)); + antenna.endShape(); + + return antenna; +} \ No newline at end of file diff --git a/magic_veneer_processing/out/magic_veneer_processing.class b/magic_veneer_processing/out/magic_veneer_processing.class index 597b1f9..d86d987 100644 Binary files a/magic_veneer_processing/out/magic_veneer_processing.class and b/magic_veneer_processing/out/magic_veneer_processing.class differ diff --git a/magic_veneer_processing/out/source/magic_veneer_processing.java b/magic_veneer_processing/out/source/magic_veneer_processing.java index 1ecc9bf..27c1131 100644 --- a/magic_veneer_processing/out/source/magic_veneer_processing.java +++ b/magic_veneer_processing/out/source/magic_veneer_processing.java @@ -22,7 +22,9 @@ Serial arduinoPort; String receivedMessage; boolean cameIntoThreshhold = false; -int radius = 0; +float placementIndicatorOffsetX = 0; +int placementIndicatorAnimationCounter = 0; +String placementIndicatorAnimationDirection = "right"; public void setup() { /* Set up screen */ @@ -35,7 +37,29 @@ public void setup() { } public void draw() { - println("Test"); + /* START - Create and animate placementIndicator */ + background(0); + placementIndicator(80, 8, placementIndicatorOffsetX); + + if (placementIndicatorAnimationCounter < 5) { + if (placementIndicatorAnimationDirection == "right" && placementIndicatorOffsetX < 30) { + placementIndicatorOffsetX += 2; + } else if (placementIndicatorAnimationDirection == "right" && placementIndicatorOffsetX <= 30) { + placementIndicatorAnimationDirection = "left"; + placementIndicatorOffsetX -= 2; + placementIndicatorAnimationCounter++; + } else if (placementIndicatorAnimationDirection == "left" && placementIndicatorOffsetX >= -30) { + placementIndicatorOffsetX -= 2; + } else if (placementIndicatorAnimationDirection == "left" && placementIndicatorOffsetX <= -30) { + placementIndicatorAnimationDirection = "right"; + placementIndicatorOffsetX += 2; + placementIndicatorAnimationCounter++; + } + } else { + placementIndicatorOffsetX = 0; + } + /* END - Create and animate placementIndicator */ + /* if ( arduinoPort.available() > 0) { String rec = arduinoPort.readStringUntil('\n'); if (rec != null) { @@ -52,6 +76,58 @@ public void draw() { fill(0); radius += 10; */ } + +public void placementIndicator(float polygonRadius, int npoints, float offsetX) { + float centerX = width / 2; + float centerY = height / 2; + + polygon(centerX + offsetX, centerY + polygonRadius * 2.75f, polygonRadius * 0.8f, npoints); + polygon(centerX + offsetX * 0.9f, centerY + polygonRadius * 1.6f, polygonRadius, npoints); + polygon(centerX + offsetX * 0.7f, centerY, polygonRadius, npoints); + polygon(centerX + offsetX * 0.3f, centerY - polygonRadius * 1.6f, polygonRadius, npoints); + head(centerX, centerY, polygonRadius, 8); +} + +public void polygon(float x, float y, float radius, int npoints) { + float angle = TWO_PI / npoints; + beginShape(); + for (float a = 0; a < TWO_PI; a += angle) { + float sx = x + cos(a) * radius; + float sy = y + sin(a) * radius; + vertex(sx, sy); + } + fill(255); + stroke(255); + endShape(CLOSE); +} + +public void head(float x, float y, float polygonRadius, int npoints) { + polygon(x, y - polygonRadius * 2.75f, polygonRadius * 0.8f, npoints); + + PShape leftAntenna = antenna(2); + PShape rightAntenna = antenna(2); + + pushMatrix(); + leftAntenna.translate(x - 45, y - polygonRadius * 3.7f); + leftAntenna.rotate(radians(350)); + shape(leftAntenna); + popMatrix(); + + pushMatrix(); + rightAntenna.translate(x + 35, y - polygonRadius * 3.7f); + rightAntenna.rotate(radians(10)); + shape(rightAntenna); + popMatrix(); +} + +public PShape antenna(float scale) { + PShape antenna = createShape(RECT, 0, 0, 5 * scale, 25 * scale); + antenna.setFill(color(255)); + antenna.setStroke(color(255)); + antenna.endShape(); + + return antenna; +} public void settings() { fullScreen(); } static public void main(String[] passedArgs) { String[] appletArgs = new String[] { "magic_veneer_processing" };