|
|
|
import processing.core.*;
|
|
|
|
import static processing.core.PApplet.*;
|
|
|
|
|
|
|
|
|
|
|
|
class Ellipse {
|
|
|
|
|
|
|
|
float centerX, centerY, width, height;
|
|
|
|
int color, brushSize;
|
|
|
|
boolean visible;
|
|
|
|
|
|
|
|
private boolean centerPointComplete, widthComplete;
|
|
|
|
|
|
|
|
Ellipse(int color, int penWidth) {
|
|
|
|
this.color = color;
|
|
|
|
this.brushSize = penWidth;
|
|
|
|
this.visible = false;
|
|
|
|
|
|
|
|
this.centerPointComplete = false;
|
|
|
|
this.widthComplete = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ellipse(float centerX, float centerY, float width, float height, int color, int penWidth) {
|
|
|
|
this.centerX = centerX;
|
|
|
|
this.centerY = centerY;
|
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
|
|
|
this.color = color;
|
|
|
|
this.brushSize = penWidth;
|
|
|
|
this.visible = true;
|
|
|
|
|
|
|
|
this.centerPointComplete = true;
|
|
|
|
this.widthComplete = 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.ellipseMode(CENTER);
|
|
|
|
p.strokeWeight(brushSize);
|
|
|
|
p.stroke(color);
|
|
|
|
p.noFill();
|
|
|
|
|
|
|
|
p.ellipse(p.convertXCoord(centerX), p.convertYCoord(centerY),
|
|
|
|
p.convertXDistance(width), p.convertYDistance(height));
|
|
|
|
|
|
|
|
p.strokeWeight(old_strokeWeight);
|
|
|
|
p.stroke(old_strokeColor);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
ClickGetter makeClickGetter(ProjectorApplet p){
|
|
|
|
return (int x, int y) -> {
|
|
|
|
if (!centerPointComplete){
|
|
|
|
centerX = x;
|
|
|
|
centerY = y;
|
|
|
|
centerPointComplete = true;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} else if (!widthComplete) {
|
|
|
|
width = abs(centerX - x) * 2;
|
|
|
|
widthComplete = true;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
height = abs(centerY - y) * 2;
|
|
|
|
visible = true;
|
|
|
|
|
|
|
|
p.commandQueue.add(makeProjectorCommand());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|