You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.3 KiB
Java

import processing.core.*;
import static processing.core.PApplet.*;
class Triangle {
float point1x, point1y, point2x, point2y, point3x, point3y;
int color, brushSize;
boolean visible;
private boolean point1complete, point2complete;
Triangle(int color, int penWidth) {
this.color = color;
this.brushSize = penWidth;
this.visible = false;
this.point1complete = false;
this.point2complete = false;
}
Triangle(float point1x, float point1y, float point2x, float point2y,
float point3x, float point3y, int color, int penWidth) {
this.point1x = point1x;
this.point1y = point1y;
this.point2x = point2x;
this.point2y = point2y;
this.point3x = point3x;
this.point3y = point3y;
this.color = color;
this.brushSize = penWidth;
this.visible = true;
this.point1complete = true;
this.point2complete = true;
}
ProjectorCommand drawCommand() {
return (ProjectorApplet p) -> {
if (!visible) {
//done drawing already
return true;
}
float old_strokeWeight = p.g.strokeWeight;
int old_strokeColor = p.g.strokeColor;
p.strokeWeight(brushSize);
p.stroke(color);
p.noFill();
p.triangle(p.convertXCoord(point1x), p.convertYCoord(point1y),
p.convertXCoord(point2x), p.convertYCoord(point2y),
p.convertXCoord(point3x), p.convertYCoord(point3y));
p.strokeWeight(old_strokeWeight);
p.stroke(old_strokeColor);
return true;
};
}
ClickGetter makeClickGetter(ProjectorApplet p) {
return (int x, int y) -> {
if (!point1complete){
point1x = x;
point1y = y;
point1complete = true;
return false;
} else if (!point2complete) {
point2x = x;
point2y = y;
point2complete = true;
return false;
} else {
point3x = x;
point3y = y;
visible = true;
p.commandQueue.add(drawCommand());
return true;
}
};
}
}