Skip to content
Snippets Groups Projects
Commit dfb1d9cb authored by BOUCHAL Stella's avatar BOUCHAL Stella
Browse files

narwi lhala

parent a0ff5b3b
No related branches found
No related tags found
No related merge requests found
package shape;
public class Decorator {
protected Shape decoratedShape;
public Decorator(Shape decoratedShape) {
this.decoratedShape = decoratedShape;
}
public int pointCounts(){
return
};
}
package shape; package shape;
public class Polygone { import javafx.geometry.Point2D;
import javafx.scene.paint.Color;
import javafx.scene.canvas.GraphicsContext;
import java.util.List;
public class Polygone extends AbstractShape {
private Color color;
private List<Point2D> points;
public Polygone(Color color, List<Point2D> points) {
this.color = color;
this.points = points;
}
@Override
public void draw(GraphicsContext gc) {
if (points.size() > 2) {
gc.setStroke(color);
gc.beginPath();
Point2D start = points.get(0);
gc.moveTo(start.getX(), start.getY());
for (int i = 1; i < points.size(); i++) {
Point2D p = points.get(i);
gc.lineTo(p.getX(), p.getY());
}
gc.closePath();
gc.stroke();
}
}
public Point2D point(int index){
if(index < 0 || index >= points.size()){
throw new IndexOutOfBoundsException("Index out of bounds");
}else {
return points.get(index);
}
}
} }
...@@ -5,23 +5,37 @@ import javafx.scene.canvas.GraphicsContext; ...@@ -5,23 +5,37 @@ import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
public class Rectangle implements Shape{ public class Rectangle implements Shape{
Color color; private Color color;
private Point2D point0, point1;
Rectangle(Color color, Point2D point0, Point2D point1){ Rectangle(Color color, Point2D point0, Point2D point1){
this.color = color; this.color = color;
this.point0 = point0;
this.point1 = point1;
} }
@Override @Override
public int pointsCount() { public int pointsCount() {
return 0; return 2;
} }
@Override @Override
public Point2D point(int index) { public Point2D point(int index) {
return null; if(index == 0) return point0;
if(index == 1) {return point1;}
else {
throw new IndexOutOfBoundsException("Index out of bounds");
}
} }
@Override @Override
public void draw(GraphicsContext context) { public void draw(GraphicsContext context) {
context.setStroke(color);
double x = Math.min(point0.getX(), point1.getX());
double y = Math.min(point0.getY(), point1.getY());
double width = Math.abs(point0.getX() - point1.getX());
double height = Math.abs(point0.getY() - point1.getY());
context.strokeRect(x, y, width, height);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment