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 25

Showing
with 419 additions and 20 deletions
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="corretto-16" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
package serializer;
import javafx.scene.canvas.Canvas;
import javafx.scene.control.Alert;
import javafx.stage.FileChooser;
import shape.Shape;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
public class DrawerWithSave extends state.Drawer {
......
package serializer;
import shape.Shape;
import shape.tp3.Shape;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collector;
public class ShapeReader {
public static List<Shape> read(File file) throws IOException {
......
package serializer;
import shape.Shape;
import shape.tp3.Shape;
import java.io.File;
import java.io.IOException;
......
......@@ -7,10 +7,8 @@ import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.stage.Stage;
import shape.tp3.*;
public class App extends Application {
......@@ -21,13 +19,24 @@ 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 rect = new Rectangle(Color.GRAY, new Point2D(150, 150), new Point2D(250, 250));
Shape decoratedRect = new BorderDecorator(new CenterDecorator(rect, 5), 5);
shapeContainer.addShape(decoratedRect);
Shape triangle = new Polygon(Color.GRAY,
new Point2D(100, 50),
new Point2D(150, 150),
new Point2D(50, 150));
Shape decoratedTriangle = new BorderDecorator(new CenterDecorator(triangle, 5), 5);
shapeContainer.addShape(decoratedTriangle);
shapeContainer.draw(graphicsContext);
root.getChildren().add(canvas);
primaryStage.setScene(new Scene(root));
primaryStage.show();
......
package shape;
package shape.tp3;
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.ArrayList;
import java.util.List;
public abstract class AbstractShape implements Shape {
protected List<Point2D> points = new ArrayList<>();
public void addPoints(Point2D... points) {
for (Point2D point : points) {
this.points.add(point);
}
}
@Override
public int pointsCount() {
return 0;
return points.size();
}
@Override
public Point2D point(int index) {
return null;
return points.get(index);
}
@Override
public void draw(GraphicsContext context) {
}
public abstract void draw(GraphicsContext graphics);
}
package shape.tp3;
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;
}
@Override
protected void drawDecoration(GraphicsContext graphicsContext) {
graphicsContext.setStroke(Color.BLACK);
for (int i = 0; i < decoratedShape.pointsCount(); i++) {
Point2D point = decoratedShape.point(i);
graphicsContext.strokeOval(point.getX() - radius, point.getY() - radius, radius * 2, radius * 2);
}
}
}
package shape.tp3;
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;
}
@Override
protected void drawDecoration(GraphicsContext graphicsContext) {
graphicsContext.setStroke(Color.RED);
Point2D center = calculateCenter();
graphicsContext.strokeOval(center.getX() - radius, center.getY() - radius, radius * 2, radius * 2);
}
private Point2D calculateCenter() {
double sumX = 0;
double sumY = 0;
for (int i = 0; i < decoratedShape.pointsCount(); i++) {
Point2D point = decoratedShape.point(i);
sumX += point.getX();
sumY += point.getY();
}
return new Point2D(sumX / decoratedShape.pointsCount(), sumY / decoratedShape.pointsCount());
}
}
package shape;
package shape.tp3;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
public class Circle implements Shape {
private Point2D center;
private double radius;
public Circle(double x, double y, double sqrt) {
public Circle(double x, double y, double radius) {
this.center = new Point2D(x, y);
this.radius = radius;
}
@Override
public int pointsCount() {
return 0;
return 1;
}
@Override
public Point2D point(int index) {
return null;
if (index == 0) {
return center;
} else {
throw new IndexOutOfBoundsException("Un cercle n'a qu'un seul point central.");
}
}
@Override
public void draw(GraphicsContext context) {
context.strokeOval(center.getX() - radius, center.getY() - radius, radius * 2, radius * 2);
}
}
package shape.tp3;
import javafx.scene.canvas.GraphicsContext;
import javafx.geometry.Point2D;
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 graphicsContext) {
decoratedShape.draw(graphicsContext);
drawDecoration(graphicsContext);
}
protected abstract void drawDecoration(GraphicsContext graphicsContext);
}
package shape.tp3;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class Polygon extends AbstractShape {
private Color color;
public Polygon(Color color, Point2D... points) {
this.color = color;
addPoints(points);
}
@Override
public void draw(GraphicsContext graphicsContext) {
graphicsContext.setFill(color);
double[] xPoints = new double[points.size()];
double[] yPoints = new double[points.size()];
for (int i = 0; i < points.size(); i++) {
xPoints[i] = points.get(i).getX();
yPoints[i] = points.get(i).getY();
}
graphicsContext.fillPolygon(xPoints, yPoints, points.size());
}
}
package shape.tp3;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class Rectangle implements Shape {
private Color color;
private Point2D point0;
private Point2D point1;
public Rectangle(Color color, Point2D point0, Point2D point1) {
this.color = color;
this.point0 = point0;
this.point1 = point1;
}
@Override
public int pointsCount() {
return 2;
}
@Override
public Point2D point(int index) {
if (index == 0) {
return point0;
} else if (index == 1) {
return point1;
} else {
throw new IndexOutOfBoundsException("Un rectangle n'a que deux points.");
}
}
@Override
public void draw(GraphicsContext context) {
context.setFill(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.fillRect(x, y, width, height);
}
}
package shape;
package shape.tp3;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
public interface Shape {
int pointsCount();
Point2D point(int index);
void draw(GraphicsContext context);
void draw(GraphicsContext graphicsContext);
}
package shape;
package shape.tp3;
import javafx.scene.canvas.GraphicsContext;
......@@ -9,10 +9,13 @@ 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)
for (Shape shape : shapes) {
shape.draw(context);
}
}
}
package shape.tp5;
import javafx.scene.canvas.GraphicsContext;
public class Circle implements Shape {
private double x, y, radius;
public Circle(double x, double y, double radius) {
this.x = x;
this.y = y;
this.radius = radius;
}
@Override
public void paint(GraphicsContext graphicsContext) {
graphicsContext.strokeOval(x - radius, y - radius, radius * 2, radius * 2);
}
@Override
public boolean contains(double x, double y) {
double dx = x - this.x;
double dy = y - this.y;
return dx * dx + dy * dy <= radius * radius;
}
@Override
public void translate(double dx, double dy) {
this.x += dx;
this.y += dy;
}
}
package shape.tp5;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import java.util.ArrayList;
import java.util.List;
class Drawer extends Canvas {
private List<Shape> shapes = new ArrayList<>();
private double startX, startY, endX, endY;
private boolean drawing = false;
public Drawer(double width, double height) {
super(width, height);
setOnMousePressed(this::handleMousePressed);
setOnMouseDragged(this::handleMouseDragged);
setOnMouseReleased(this::handleMouseReleased);
}
private void handleMousePressed(MouseEvent event) {
if (event.getButton() == MouseButton.PRIMARY) {
startX = event.getX();
startY = event.getY();
drawing = true;
}
}
private void handleMouseDragged(MouseEvent event) {
if (drawing) {
endX = event.getX();
endY = event.getY();
repaint();
}
}
private void handleMouseReleased(MouseEvent event) {
if (drawing) {
endX = event.getX();
endY = event.getY();
shapes.add(new Rectangle(Math.min(startX, endX), Math.min(startY, endY),
Math.abs(endX - startX), Math.abs(endY - startY)));
drawing = false;
repaint();
}
}
public void repaint() {
GraphicsContext gc = getGraphicsContext2D();
gc.clearRect(0, 0, getWidth(), getHeight());
for (Shape shape : shapes) {
shape.paint(gc);
}
if (drawing) {
gc.setStroke(javafx.scene.paint.Color.BLACK);
gc.strokeRect(Math.min(startX, endX), Math.min(startY, endY),
Math.abs(endX - startX), Math.abs(endY - startY));
}
}
}
package shape.tp5;
import javafx.scene.canvas.GraphicsContext;
public class Rectangle implements Shape {
private double x, y, width, height;
public Rectangle(double x, double y, double width, double height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
@Override
public void paint(GraphicsContext graphicsContext) {
graphicsContext.fillRect(x, y, width, height);
}
@Override
public boolean contains(double x, double y) {
return x >= this.x && x <= this.x + width && y >= this.y && y <= this.y + height;
}
@Override
public void translate(double dx, double dy) {
this.x += dx;
this.y += dy;
}
}
package shape.tp5;
import javafx.scene.canvas.GraphicsContext;
public interface Shape {
void paint(GraphicsContext graphicsContext);
boolean contains(double x, double y);
void translate(double dx, double dy);
}
package shape.tp5;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class ShapeApp extends Application {
@Override
public void start(Stage primaryStage) {
Drawer drawer = new Drawer(400, 400);
StackPane root = new StackPane(drawer);
Scene scene = new Scene(root, 400, 400);
primaryStage.setTitle("Éditeur de formes");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
\ No newline at end of file
package state;
import javafx.scene.canvas.Canvas;
import shape.Circle;
import shape.Shape;
import shape.tp3.Shape;
import java.util.ArrayList;
import java.util.List;
......