Skip to content
Snippets Groups Projects
Circle.java 1.37 KiB
Newer Older
  • Learn to ignore specific revisions
  • BasileCouetoux's avatar
    BasileCouetoux committed
    package shape;
    
    import javafx.geometry.Point2D;
    import javafx.scene.canvas.GraphicsContext;
    
    import javafx.scene.paint.Color;
    
    BasileCouetoux's avatar
    BasileCouetoux committed
    
    public class Circle implements Shape {
    
    
        private double radius, x, y;
    
    MANSOUR Chadi's avatar
    MANSOUR Chadi committed
        private Color fillColor;
    
    
        public Circle(double x, double y, double radius) {
            this.x = x;
            this.y = y;
            this.radius = radius;
    
    MANSOUR Chadi's avatar
    MANSOUR Chadi committed
            this.fillColor = Color.GREEN;
    
    BasileCouetoux's avatar
    BasileCouetoux committed
        }
    
    
    BasileCouetoux's avatar
    BasileCouetoux committed
        @Override
    
        public void paint(GraphicsContext graphicsContext) {
    
    MANSOUR Chadi's avatar
    MANSOUR Chadi committed
            graphicsContext.setStroke(Color.BLACK);
            if(isFinished) {
                graphicsContext.setFill(Color.GREEN);
                graphicsContext.fillOval(x - radius, y - radius, 2 * radius, 2 * radius);
            }
    
            graphicsContext.strokeOval(x-radius, y-radius, 2 * radius, 2 * radius);
    
    BasileCouetoux's avatar
    BasileCouetoux committed
        }
    
        @Override
    
        public boolean contains(double x, double y) {
    
            double dx = x - this.x;
            double dy = y - this.y;
            return Math.sqrt(dx*dx + dy*dy) <= radius;
    
    BasileCouetoux's avatar
    BasileCouetoux committed
        }
    
        @Override
    
        public void translate(double dx, double dy) {
            this.x += dx;
            this.y += dy;
    
    BasileCouetoux's avatar
    BasileCouetoux committed
        }
    
    MANSOUR Chadi's avatar
    MANSOUR Chadi committed
    
        @Override
        public boolean isFinished() {
            return true;
        }
    
    
        public void updateRadius(double newX, double newY) {
            this.radius = Math.sqrt(Math.pow(newX - this.x, 2) + Math.pow(newY - this.y, 2));
        }
    
    MANSOUR Chadi's avatar
    MANSOUR Chadi committed
        public void setFillColor(Color fillColor) {
            this.fillColor = fillColor;
        }
    
    BasileCouetoux's avatar
    BasileCouetoux committed
    }