Skip to content
Snippets Groups Projects
Commit c0b4692d authored by AREZKI Celia's avatar AREZKI Celia
Browse files

add of CenterDecorator class , it adds a circle around the center of the shape

parent 4ed94f69
No related branches found
No related tags found
No related merge requests found
Checking pipeline status
package shape;
import javafx.scene.canvas.GraphicsContext;
import javafx.geometry.Point2D;
import javafx.scene.paint.Color;
public class CenterDecorator extends Decorator {
private double radius;
public CenterDecorator(Shape decoratedShape, double radius) {
super(decoratedShape);
this.radius = radius;
}
@Override
protected void drawDecoration(GraphicsContext graphicsContext) {
graphicsContext.setStroke(Color.RED);
double centerX = 0, centerY = 0;
for (int i = 0; i < decoratedShape.pointsCount(); i++) {
Point2D point = decoratedShape.point(i);
centerX += point.getX();
centerY += point.getY();
}
centerX /= decoratedShape.pointsCount();
centerY /= decoratedShape.pointsCount();
graphicsContext.strokeOval(centerX - radius, centerY - radius, radius * 2, radius * 2);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment