Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
1 result

Target

Select target project
  • b21228304/graphic-2020-2-0
  • l21221596/graphic-2020
  • c19014407/graphic-2020
  • b23019494/graphic-2020
  • g21212987/graphic-2020
  • couetoux.b/graphic-2020
  • s22029480/graphic-2020
  • c23025119/tp-3-graphique
  • m19023837/graphic-2020-tp-5
  • s22029480/graphic-tp-4
  • m19023837/graphic-2020-tp-7
  • n22021899/tp-3-programmation-conception
  • r24025701/graphic-2020
  • a23022716/exo-2-tp-3-algo
  • m23000189/graphic-2024
  • b21228304/graphic-2020
  • t21234458/graphic-2020
  • v23014723/graphic-2020
  • h22021483/graphic-2020
  • t21234458/graphic-2020-tiakout-khaled
  • m19023837/graphic-2020-chadi
  • b20031964/graphic-2020
22 results
Select Git revision
  • master
1 result
Show changes
Commits on Source (3)
package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import java.util.List;
public abstract class AbstractShape implements Shape {
private List<Point2D> points;
public AbstractShape(List<Point2D> points) {
this.points = points;
}
public void addPoints(Point2D... points){
for (Point2D point: points)
this.points.add(point);
}
@Override
public int pointsCount() {
return points.size();
}
@Override
public Point2D point(int index) {
return index < points.size() ? points.get(index) : null;
}
@Override
public void draw(GraphicsContext context) {
if (pointsCount()>0){
context.beginPath();
context.moveTo(point(0).getX(), point(0).getY());
for (int i = 1; i<pointsCount(); i++){
context.lineTo(point(i).getX(),point(i).getY());
}
context.closePath();
context.stroke();
}
}
}
package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class BorderDecorator extends Decorator {
private double radius;
public BorderDecorator(Shape decoratedShape ,double radius) {
super(decoratedShape);
this.radius = radius;
}
protected void drawDecoration(GraphicsContext context) {
context.setStroke(Color.BLACK);
context.setLineWidth(2);
for (int i=0; i<pointsCount(); i++){
Point2D point = point(i);
context.strokeOval(point.getX() - radius, point.getY()- radius,radius*2,radius*2);
}
}
}
package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class CenterDecorator extends Decorator{
private double radius;
public CenterDecorator(Shape decoratedShape, double radius) {
super(decoratedShape);
this.radius = radius;
}
protected void drawDecoration(GraphicsContext context) {
double centerX = 0;
double centerY = 0;
for (int i =0; i<pointsCount(); i++){
Point2D point = point(i);
centerX += point.getX();
centerY += point.getY();
}
centerX /= pointsCount();
centerY /= pointsCount();
context.setStroke(Color.RED);
context.setLineWidth(2);
context.strokeOval(centerX-radius, centerY-radius, radius*2,radius*2);
}
}
package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
public abstract class Decorator implements Shape {
protected Shape decoratedshape;
public Decorator(Shape decoratedShape) {
this.decoratedshape = decoratedShape;
}
@Override
public int pointsCount() {
return decoratedshape.pointsCount();
}
@Override
public Point2D point(int index) {
return decoratedshape.point(index);
}
@Override
public void draw(GraphicsContext context) {
decoratedshape.draw(context);
drawDecoration(context);
}
protected void drawDecoration(GraphicsContext context) {
}
}
package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import java.util.List;
public class Polygon extends AbstractShape {
private Color color;
public Polygon(Color color, Point2D... points) {
super(List.of(points));
this.color = color;
}
@Override
public int pointsCount() {
return super.pointsCount();
}
@Override
public Point2D point(int index) {
return super.point(index);
}
@Override
public void draw(GraphicsContext context) {
context.setFill(color);
super.draw(context);
context.fill();
}
}
......@@ -4,24 +4,30 @@ import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class Rectangle implements Shape{
Color color;
import java.util.List;
public class Rectangle extends AbstractShape{
private Color color;
Rectangle(Color color, Point2D point0, Point2D point1){
super(List.of(point0, new Point2D(point1.getX(),point0.getY()),
point1,new Point2D(point0.getX(),point1.getY())));
this.color = color;
}
@Override
public int pointsCount() {
return 0;
return super.pointsCount();
}
@Override
public Point2D point(int index) {
return null;
return super.point(index);
}
@Override
public void draw(GraphicsContext context) {
context.setFill(color);
super.draw(context);
context.fill();
}
}
......@@ -9,7 +9,9 @@ public class ShapeContainer{
private List<Shape> shapes = new ArrayList<>();
public void addShape(Shape shape){}
public void addShape(Shape shape){
shapes.add(shape);
}
public void draw(GraphicsContext context){
for(Shape shape : shapes)
......