Class Turtle

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void backward()
      Move this Turtle backward one unit.
      void backward​(double distance)
      Move this Turtle backward the given number of units.
      void forward()
      Move this Turtle foward one unit in the heading direction.
      void forward​(double distance)
      Move this Turtle forward the given number of units in the heading direction.
      double getHeading()
      Get the current heading of this Turtle.
      double getXPos()
      Get the current x position of this Turtle.
      double getYPos()
      Get the current y position of this Turtle.
      void home()
      Move this Turtle to the coordinates (0, 0) and give it the heading of 0 degrees.
      boolean isPenDown()
      Check if this Turtle's pen is down.
      void left()
      Turn this Turtle 90 degrees counterclockwise.
      void move​(double distance)
      Same as the forward() method but without building a LineSegment.
      void moveTo​(double x, double y)
      Move this Turtle to the given (x, y) location.
      void penDown()
      Set this Turtle's pen down.
      void penUp()
      Lift this Turtle's pen up.
      void resize​(double s)
      Change the length of the step size by the factor s.
      void right()
      Turn this Turtle 90 degrees clockwise.
      void setHeading​(double heading)
      Set the heading of this Turtle.
      void setPenDown​(boolean value)
      Set this Turtle's penDown variable.
      String toString()
      For debugging.
      void turn​(double degrees)
      Turn this Turtle by the given angle in degrees.
      void turnToFace​(double x, double y)
      Turn this Turtle towards the given (x, y).
      void turnToFace​(Turtle turtle)
      Turn this Turtle to face another Turtle.
    • Constructor Detail

      • Turtle

        public Turtle​(Model model)
        Parameters:
        model - a reference to the {link Model} that this Turtle is builing
        Throws:
        NullPointerException - if model is null
      • Turtle

        public Turtle​(Model model,
                      double z)
        Parameters:
        model - a reference to the Model that this Turtle is builing
        z - the z-plane for this Turtle
        Throws:
        NullPointerException - if model is null
      • Turtle

        public Turtle​(Model model,
                      double xHome,
                      double yHome,
                      double z)
        Parameters:
        model - a reference to the Model that this Turtle is builing
        xHome - the intial x-coordinate for this Turtle
        yHome - the intial y-coordinate for this Turtle
        z - the z-plane for this Turtle
        Throws:
        NullPointerException - if model is null
      • Turtle

        public Turtle​(Model model,
                      String name,
                      double xHome,
                      double yHome,
                      double z)
        Parameters:
        model - a reference to the Model that this Turtle is builing
        name - a String that is a name for this Turtle
        xHome - the intial x-coordinate for this Turtle
        yHome - the intial y-coordinate for this Turtle
        z - the z-plane for this Turtle
        Throws:
        NullPointerException - if model is null
        NullPointerException - if name is null
    • Method Detail

      • isPenDown

        public boolean isPenDown()
        Check if this Turtle's pen is down.
        Returns:
        true if down else false
      • setPenDown

        public void setPenDown​(boolean value)
        Set this Turtle's penDown variable.
        Parameters:
        value - value for this Turtle's penDown variable
      • penDown

        public void penDown()
        Set this Turtle's pen down.
      • penUp

        public void penUp()
        Lift this Turtle's pen up.
      • getXPos

        public double getXPos()
        Get the current x position of this Turtle.
        Returns:
        the x position of this Turtle
      • getYPos

        public double getYPos()
        Get the current y position of this Turtle.
        Returns:
        the y position of this Turtle
      • getHeading

        public double getHeading()
        Get the current heading of this Turtle.
        Returns:
        the heading in degrees of this Turtle
      • setHeading

        public void setHeading​(double heading)
        Set the heading of this Turtle.
        Parameters:
        heading - new heading in degrees for this Turtle
      • right

        public void right()
        Turn this Turtle 90 degrees clockwise.
      • left

        public void left()
        Turn this Turtle 90 degrees counterclockwise.
      • turn

        public void turn​(double degrees)
        Turn this Turtle by the given angle in degrees. Use positive angles to turn clockwise and negative angles to turn counterclockwise.
        Parameters:
        degrees - the amount to turn this Turtle in degrees
      • turnToFace

        public void turnToFace​(Turtle turtle)
        Turn this Turtle to face another Turtle.
        Parameters:
        turtle - the Turtle to turn towards
      • turnToFace

        public void turnToFace​(double x,
                               double y)
        Turn this Turtle towards the given (x, y).
        Parameters:
        x - the x to turn this Turtle towards
        y - the y to turn this Turtle towards
      • home

        public void home()
        Move this Turtle to the coordinates (0, 0) and give it the heading of 0 degrees.
      • moveTo

        public void moveTo​(double x,
                           double y)
        Move this Turtle to the given (x, y) location.
        Parameters:
        x - the x-coordinate to move this Turtle to
        y - the y-coordinate to move this Turtle to
      • forward

        public void forward()
        Move this Turtle foward one unit in the heading direction.
      • backward

        public void backward()
        Move this Turtle backward one unit.
      • backward

        public void backward​(double distance)
        Move this Turtle backward the given number of units.
        Parameters:
        distance - the distance to walk this Turtle backward
      • forward

        public void forward​(double distance)
        Move this Turtle forward the given number of units in the heading direction. If the pen is down, then add two Vertex objects and a LineSegment object to the underlying Turtle.
        Parameters:
        distance - the distance to walk this Turtle forward in the heading direction
      • move

        public void move​(double distance)
        Same as the forward() method but without building a LineSegment.

        This is part of "Turtle Geometry" as defined by Ronald Goldman.

        https://www.clear.rice.edu/comp360/lectures/old/TurtlesGraphicL1New.pdf https://people.engr.tamu.edu/schaefer/research/TurtlesforCADRevised.pdf https://www.routledge.com/An-Integrated-Introduction-to-Computer-Graphics-and-Geometric-Modeling/Goldman/p/book/9781138381476

        Parameters:
        distance - the distance to walk this Turtle forward in the heading direction
      • resize

        public void resize​(double s)
        Change the length of the step size by the factor s.

        This is part of "Turtle Geometry" as defined by Ronald Goldman.

        Parameters:
        s - scaling factor for the new stepSize