Create placementIndicator with function
This commit is contained in:
parent
a443b5b412
commit
a4f64ceb09
3 changed files with 157 additions and 9 deletions
|
|
@ -4,7 +4,9 @@ Serial arduinoPort;
|
||||||
String receivedMessage;
|
String receivedMessage;
|
||||||
boolean cameIntoThreshhold = false;
|
boolean cameIntoThreshhold = false;
|
||||||
|
|
||||||
int radius = 0;
|
float placementIndicatorOffsetX = 0;
|
||||||
|
int placementIndicatorAnimationCounter = 0;
|
||||||
|
String placementIndicatorAnimationDirection = "right";
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
/* Set up screen */
|
/* Set up screen */
|
||||||
|
|
@ -17,7 +19,29 @@ void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw() {
|
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) {
|
/* if ( arduinoPort.available() > 0) {
|
||||||
String rec = arduinoPort.readStringUntil('\n');
|
String rec = arduinoPort.readStringUntil('\n');
|
||||||
if (rec != null) {
|
if (rec != null) {
|
||||||
|
|
@ -28,9 +52,57 @@ void draw() {
|
||||||
if (receivedMessage != null && receivedMessage.contains("isWithinThreshhold")) {
|
if (receivedMessage != null && receivedMessage.contains("isWithinThreshhold")) {
|
||||||
cameIntoThreshhold = true;
|
cameIntoThreshhold = true;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
}
|
||||||
circle(width / 2, height / 2, radius);
|
|
||||||
fill(0);
|
void placementIndicator(float polygonRadius, int npoints, float offsetX) {
|
||||||
radius += 10; */
|
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;
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
|
@ -22,7 +22,9 @@ Serial arduinoPort;
|
||||||
String receivedMessage;
|
String receivedMessage;
|
||||||
boolean cameIntoThreshhold = false;
|
boolean cameIntoThreshhold = false;
|
||||||
|
|
||||||
int radius = 0;
|
float placementIndicatorOffsetX = 0;
|
||||||
|
int placementIndicatorAnimationCounter = 0;
|
||||||
|
String placementIndicatorAnimationDirection = "right";
|
||||||
|
|
||||||
public void setup() {
|
public void setup() {
|
||||||
/* Set up screen */
|
/* Set up screen */
|
||||||
|
|
@ -35,7 +37,29 @@ public void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw() {
|
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) {
|
/* if ( arduinoPort.available() > 0) {
|
||||||
String rec = arduinoPort.readStringUntil('\n');
|
String rec = arduinoPort.readStringUntil('\n');
|
||||||
if (rec != null) {
|
if (rec != null) {
|
||||||
|
|
@ -52,6 +76,58 @@ public void draw() {
|
||||||
fill(0);
|
fill(0);
|
||||||
radius += 10; */
|
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(); }
|
public void settings() { fullScreen(); }
|
||||||
static public void main(String[] passedArgs) {
|
static public void main(String[] passedArgs) {
|
||||||
String[] appletArgs = new String[] { "magic_veneer_processing" };
|
String[] appletArgs = new String[] { "magic_veneer_processing" };
|
||||||
|
|
|
||||||
Reference in a new issue