Class Square

java.lang.Object
com.gigamonkeys.bhs.shapes.Square

public class Square extends Object
Simple square shape to be drawn on an image via a java.awt.Graphics object.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Square(Graphics g, int x, int y, int size)
    Constructs a new Square with the specified graphics context, position, size, and a default color of black.
    Square(Graphics g, int x, int y, int size, Color color)
    Constructs a new Square with the specified graphics context, position, size, and color.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Draws the outline of the square using its current properties.
    void
    embiggen(double percentage)
    Increases the size of the square by a percentage of its current size, keeping its top-left corner in the same position.
    void
    embiggenFromCenter(double percentage)
    Increases the size of the square by a percentage of its current size, keeping its center in the same position.
    void
    Fills the square using its current properties.
    Returns the color of the square.
    double
    Returns the rotation angle of the square in radians.
    int
    Returns the lenth of the side of the square.
    int
    Returns the x-coordinate of the top-left corner of the square.
    int
    Returns the y-coordinate of the top-left corner of the square.
    void
    move(int dx, int dy)
    Moves the square by the specified deltas along the x and y axes.
    void
    moveTo(int x, int y)
    Sets the position of the square to the specified coordinates.
    void
    rotate(double radians)
    Rotates the square by the specified radians around its center.
    void
    setColor(Color color)
    Sets the color of the square to the specified value.
    void
    shrink(double percentage)
    Shrinks the size of the square by a percentage of its current size, keeping its top-left corner in the same position.
    void
    shrinkToCenter(double percentage)
    Shrinks the size of the square by a percentage of its current size, keeping its center in the same position.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Square

      public Square(Graphics g, int x, int y, int size, Color color)
      Constructs a new Square with the specified graphics context, position, size, and color.
      Parameters:
      g - the graphics context to be used for drawing.
      x - the x-coordinate of the top-left corner of the square.
      y - the y-coordinate of the top-left corner of the square.
      size - the side length of the square.
      color - the color of the square.
    • Square

      public Square(Graphics g, int x, int y, int size)
      Constructs a new Square with the specified graphics context, position, size, and a default color of black.
      Parameters:
      g - the graphics context to be used for drawing.
      x - the x-coordinate of the top-left corner of the square.
      y - the y-coordinate of the top-left corner of the square.
      size - the side length of the square.
  • Method Details

    • getX

      public int getX()
      Returns the x-coordinate of the top-left corner of the square.
      Returns:
      the x-coordinate.
    • getY

      public int getY()
      Returns the y-coordinate of the top-left corner of the square.
      Returns:
      the y-coordinate.
    • getSize

      public int getSize()
      Returns the lenth of the side of the square.
      Returns:
      the size of the square.
    • getColor

      public Color getColor()
      Returns the color of the square.
      Returns:
      the current color.
    • getRotation

      public double getRotation()
      Returns the rotation angle of the square in radians.
      Returns:
      the rotation angle in radians.
    • setColor

      public void setColor(Color color)
      Sets the color of the square to the specified value.
      Parameters:
      color - the new color to set.
    • move

      public void move(int dx, int dy)
      Moves the square by the specified deltas along the x and y axes.
      Parameters:
      dx - the amount to move in the x direction.
      dy - the amount to move in the y direction.
    • moveTo

      public void moveTo(int x, int y)
      Sets the position of the square to the specified coordinates.
      Parameters:
      x - the new x-coordinate.
      y - the new y-coordinate.
    • rotate

      public void rotate(double radians)
      Rotates the square by the specified radians around its center.
      Parameters:
      radians - the angle of rotation in radians.
    • shrink

      public void shrink(double percentage)
      Shrinks the size of the square by a percentage of its current size, keeping its top-left corner in the same position.
      Parameters:
      percentage - the percentage to shrink, where 0.1 represents 10%.
    • shrinkToCenter

      public void shrinkToCenter(double percentage)
      Shrinks the size of the square by a percentage of its current size, keeping its center in the same position.
      Parameters:
      percentage - the percentage to shrink, where 0.1 represents 10%.
    • embiggen

      public void embiggen(double percentage)
      Increases the size of the square by a percentage of its current size, keeping its top-left corner in the same position.
      Parameters:
      percentage - the percentage to increase, where 0.1 represents 10%.
    • embiggenFromCenter

      public void embiggenFromCenter(double percentage)
      Increases the size of the square by a percentage of its current size, keeping its center in the same position.
      Parameters:
      percentage - the percentage to increase, where 0.1 represents 10%.
    • draw

      public void draw()
      Draws the outline of the square using its current properties.
    • fill

      public void fill()
      Fills the square using its current properties.