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.

75 lines
1.5 KiB
Java

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;
}
ProjectorCommand makeProjectorCommand() {
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;
p.commandQueue.add(makeProjectorCommand());
return true;
}
};
}
}