import objectdraw.*; import java.awt.Color; public class FancyBasketball { // default color of the ball private static final Color BALL_ORANGE = new Color(250, 85, 10); // the interior of the ball private FilledOval body; // the black frame around the ball private FramedOval border; // size and starting angles for cut arc in degrees private static final int CUTSIZE = 100; private static final int RIGHTCUTSTART = 90 + (180 - CUTSIZE) / 2; private static final int LEFTCUTSTART = 270 + (180 - CUTSIZE) / 2; // the two curves on the sides of the ball private FramedArc leftCut, rightCut; // the vertical and horizontal lines through the ball private Line vert, horiz; private double xpos; private double ypos; public FancyBasketball(Location pos, int size, DrawingCanvas theCanvas) { this(pos.getX(), pos.getY(), size, theCanvas); } public FancyBasketball(double xpos, double ypos, int size, DrawingCanvas theCanvas) { this.xpos = xpos; this.ypos = ypos; body = new FilledOval(xpos, ypos, size, size, theCanvas); border = new FramedOval(xpos, ypos, size, size, theCanvas); body.setColor(BALL_ORANGE); // draw the lines and arcs that make it look like a basketball rightCut = new FramedArc(xpos + size * 2 / 3, ypos, size, size, RIGHTCUTSTART, CUTSIZE, theCanvas); leftCut = new FramedArc(xpos - size * 2 / 3, ypos, size, size, LEFTCUTSTART, CUTSIZE, theCanvas); vert = new Line(xpos + size / 2, ypos, xpos + size / 2, ypos + size, theCanvas); horiz = new Line(xpos, ypos + size / 2, xpos + size, ypos + size / 2, theCanvas); } // startingX, startingY public void returnToStart() { this.moveTo(xpos, ypos); } public void move(double xdist, double ydist) { body.move(xdist, ydist); border.move(xdist, ydist); vert.move(xdist, ydist); horiz.move(xdist, ydist); rightCut.move(xdist, ydist); leftCut.move(xdist, ydist); } public void moveTo(double xpos, double ypos) { this.move(xpos - this.getX(), ypos - this.getY()); } public void moveTo(Location loc) { this.moveTo(loc.getX(), loc.getY()); } public void moveToCorner() { this.moveTo(0, 0); } public boolean contains(Location point) { return body.contains(point); } public double getX() { return body.getX(); } public double getY() { return body.getY(); } public Location getCenter() { return new Location(body.getX() + body.getWidth() / 2, body.getY() + body.getHeight() / 2); } public void setColor(Color newColor) { body.setColor(newColor); } }