2016-07-10 09:03:16 -07:00
|
|
|
import processing.core.*;
|
|
|
|
import static processing.core.PApplet.*;
|
|
|
|
|
|
|
|
|
|
|
|
class Line {
|
|
|
|
float x1, y1, x2, y2;
|
|
|
|
int color, brushSize;
|
|
|
|
boolean visible;
|
|
|
|
|
|
|
|
private boolean point1complete;
|
|
|
|
|
|
|
|
Line(int color, int penWidth) {
|
|
|
|
this.color = color;
|
|
|
|
this.brushSize = penWidth;
|
|
|
|
this.visible = true;
|
|
|
|
|
|
|
|
this.point1complete = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Line(float x1, float y1, float x2, float y2, int color, int penWidth) {
|
|
|
|
this.x1 = x1;
|
|
|
|
this.y1 = y1;
|
|
|
|
this.x2 = x2;
|
|
|
|
this.y2 = y2;
|
|
|
|
this.color = color;
|
|
|
|
this.brushSize = penWidth;
|
|
|
|
this.visible = true;
|
|
|
|
|
|
|
|
this.point1complete = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-10 17:51:01 -07:00
|
|
|
ProjectorCommand makeProjectorCommand() {
|
2016-07-10 09:03:16 -07:00
|
|
|
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.line(p.convertXCoord(x1), p.convertYCoord(y1),
|
|
|
|
p.convertXCoord(x2), p.convertYCoord(y2));
|
|
|
|
|
|
|
|
p.strokeWeight(old_strokeWeight);
|
|
|
|
p.stroke(old_strokeColor);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
ClickGetter makeClickGetter(ProjectorApplet p) {
|
|
|
|
return (int x, int y) -> {
|
|
|
|
if (!point1complete){
|
|
|
|
x1 = x;
|
|
|
|
y1 = y;
|
|
|
|
point1complete = true;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
x2 = x;
|
|
|
|
y2 = y;
|
|
|
|
visible = true;
|
|
|
|
|
2016-07-10 17:51:01 -07:00
|
|
|
p.commandQueue.add(makeProjectorCommand());
|
2016-07-10 09:03:16 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|