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 (4)
package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public abstract class AbstractShape implements Shape {
protected List<Point2D> points = new ArrayList<>();
public void addPoints(Point2D... points){
this.points.addAll(Arrays.asList(points));
}
@Override
public int pointsCount() {
return points.size();
}
@Override
public Point2D point(int index) {
if( index >= 0 && index < points.size()){
return points.get(index);
}else {
throw new IndexOutOfBoundsException("Index out of bounds");
}
}
@Override
public abstract void draw(GraphicsContext context) ;
}
......@@ -21,12 +21,20 @@ public class App extends Application {
@Override
public void start(Stage primaryStage) {
Group root = new Group();
Canvas canvas = new Canvas(130, 110);
Canvas canvas = new Canvas(300, 300);
GraphicsContext graphicsContext = canvas.getGraphicsContext2D();
ShapeContainer shapeContainer = new ShapeContainer();
graphicsContext.setFill(Color.AQUAMARINE);
graphicsContext.fillOval(10,10,10,10);
shapeContainer.addShape(new Rectangle(Color.BLUE,new Point2D(10,10), new Point2D(40,40)));
Shape rectangle = new Rectangle(Color.BLUE, new Point2D(50, 50), new Point2D(150, 100));
rectangle = new BorderDecorator(rectangle, 10);
rectangle = new CenterDecorator(rectangle, 5);
shapeContainer.addShape(rectangle);
Shape polygone = new Polygon(Color.YELLOW, new Point2D(210,100),new Point2D(250,100),new Point2D(150,160), new Point2D(90,100));
polygone = new BorderDecorator(polygone, 15);
polygone = new CenterDecorator(polygone, 5);
shapeContainer.addShape(polygone);
shapeContainer.draw(graphicsContext);
root.getChildren().add(canvas);
primaryStage.setScene(new Scene(root));
......
package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class BorderDecorator extends Decorator {
private final 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);
if (decoratedshape.pointsCount() >= 2){
Point2D point0 = decoratedshape.point(0);
Point2D point1 = decoratedshape.point(1);
double x = Math.min(point0.getX(), point1.getX());
double y = Math.min(point0.getY(), point1.getY());
double width = Math.abs(point1.getX() - point0.getX());
double height = Math.abs(point1.getY() - point0.getY());
context.strokeRoundRect(x,y, width,height,radius, radius);
}
}
}
package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class CenterDecorator extends Decorator{
private final double radius;
public CenterDecorator(Shape decoratedShape, double radius) {
super(decoratedShape);
this.radius = radius;
}
protected void drawDecoration(GraphicsContext context) {
if (decoratedshape.pointsCount() >= 2) {
Point2D point0 = decoratedshape.point(0);
Point2D point1 = decoratedshape.point(1);
double centerX = point0.getX() + point1.getX() / 2;
double centerY = point0.getY() + point1.getY() / 2;
context.setFill(Color.RED);
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 final 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 abstract 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 final Color color;
public Polygon(Color color, Point2D... points) {
this.color = color;
addPoints(points);
}
@Override
public void draw(GraphicsContext context) {
context.setStroke(color);
context.beginPath();
context.moveTo(points.get(0).getX(), points.get(0).getY());
for (int i = 1; i < pointsCount() ; i++) {
context.lineTo(points.get(i).getX(), points.get(i).getY());
}
context.closePath();
context.stroke();
}
}
......@@ -4,24 +4,28 @@ import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class Rectangle implements Shape{
Color color;
Rectangle(Color color, Point2D point0, Point2D point1){
this.color = color;
}
import java.util.List;
@Override
public int pointsCount() {
return 0;
}
public class Rectangle extends AbstractShape{
private final Color color;
@Override
public Point2D point(int index) {
return null;
public Rectangle(Color color, Point2D point0, Point2D point1){
this.color = color;
addPoints(point0, point1);
}
@Override
public void draw(GraphicsContext context) {
context.setStroke(color);
Point2D point0 = points.get(0);
Point2D point1 = points.get(1);
double x = Math.min(point0.getX(), point1.getX());
double y = Math.min(point0.getY(), point1.getY());
double width = Math.abs(point1.getX() - point0.getX());
double height = Math.abs(point1.getY() - point0.getY());
context.strokeRect(x,y,width,height);
}
}
......@@ -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)
......