Package renderer.models_L.turtlegraphics
Class Turtle
- java.lang.Object
-
- renderer.models_L.turtlegraphics.Turtle
-
- Direct Known Subclasses:
HilbertCurveTurtle
,NinjaTurtle
,PentagasketTurtle
,PolygasketTurtle
,SierpinskiCurveTurtle
,SierpinskiTurtle
,SpiralTurtle
public class Turtle extends Object
https://www.clear.rice.edu/comp360/lectures/K10188_C001.pdf
-
-
Constructor Summary
Constructors Constructor Description Turtle(Model model)
Turtle(Model model, double z)
Turtle(Model model, double xHome, double yHome, double z)
Turtle(Model model, String name)
Turtle(Model model, String name, double z)
Turtle(Model model, String name, double xHome, double yHome, double z)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
backward()
Move thisTurtle
backward one unit.void
backward(double distance)
Move thisTurtle
backward the given number of units.void
forward()
Move thisTurtle
foward one unit in the heading direction.void
forward(double distance)
Move thisTurtle
forward the given number of units in the heading direction.double
getHeading()
Get the current heading of thisTurtle
.double
getXPos()
Get the current x position of thisTurtle
.double
getYPos()
Get the current y position of thisTurtle
.void
home()
Move thisTurtle
to the coordinates (0, 0) and give it the heading of 0 degrees.boolean
isPenDown()
Check if thisTurtle
's pen is down.void
left()
Turn thisTurtle
90 degrees counterclockwise.void
move(double distance)
Same as the forward() method but without building aLineSegment
.void
moveTo(double x, double y)
Move thisTurtle
to the given (x, y) location.void
penDown()
Set thisTurtle
's pen down.void
penUp()
Lift thisTurtle
's pen up.void
resize(double s)
Change the length of the step size by the factors
.void
right()
Turn thisTurtle
90 degrees clockwise.void
setHeading(double heading)
Set the heading of thisTurtle
.void
setPenDown(boolean value)
Set thisTurtle
's penDown variable.String
toString()
For debugging.void
turn(double degrees)
Turn thisTurtle
by the given angle in degrees.void
turnToFace(double x, double y)
Turn thisTurtle
towards the given (x, y).void
turnToFace(Turtle turtle)
Turn thisTurtle
to face anotherTurtle
.
-
-
-
Constructor Detail
-
Turtle
public Turtle(Model model)
- Parameters:
model
- a reference to the {link Model} that thisTurtle
is builing- Throws:
NullPointerException
- ifmodel
isnull
-
Turtle
public Turtle(Model model, String name)
- Parameters:
model
- a reference to theModel
that thisTurtle
is builingname
- aString
that is a name for thisTurtle
- Throws:
NullPointerException
- ifmodel
isnull
NullPointerException
- ifname
isnull
-
Turtle
public Turtle(Model model, double z)
- Parameters:
model
- a reference to theModel
that thisTurtle
is builingz
- the z-plane for thisTurtle
- Throws:
NullPointerException
- ifmodel
isnull
-
Turtle
public Turtle(Model model, String name, double z)
- Parameters:
model
- a reference to theModel
that thisTurtle
is builingname
- aString
that is a name for thisTurtle
z
- the z-plane for thisTurtle
- Throws:
NullPointerException
- ifmodel
isnull
NullPointerException
- ifname
isnull
-
Turtle
public Turtle(Model model, double xHome, double yHome, double z)
- Parameters:
model
- a reference to theModel
that thisTurtle
is builingxHome
- the intial x-coordinate for thisTurtle
yHome
- the intial y-coordinate for thisTurtle
z
- the z-plane for thisTurtle
- Throws:
NullPointerException
- ifmodel
isnull
-
Turtle
public Turtle(Model model, String name, double xHome, double yHome, double z)
- Parameters:
model
- a reference to theModel
that thisTurtle
is builingname
- aString
that is a name for thisTurtle
xHome
- the intial x-coordinate for thisTurtle
yHome
- the intial y-coordinate for thisTurtle
z
- the z-plane for thisTurtle
- Throws:
NullPointerException
- ifmodel
isnull
NullPointerException
- ifname
isnull
-
-
Method Detail
-
isPenDown
public boolean isPenDown()
Check if thisTurtle
's pen is down.- Returns:
- true if down else false
-
setPenDown
public void setPenDown(boolean value)
Set thisTurtle
's penDown variable.- Parameters:
value
- value for thisTurtle
's penDown variable
-
penDown
public void penDown()
Set thisTurtle
's pen down.
-
penUp
public void penUp()
Lift thisTurtle
's pen up.
-
getXPos
public double getXPos()
Get the current x position of thisTurtle
.- Returns:
- the x position of this
Turtle
-
getYPos
public double getYPos()
Get the current y position of thisTurtle
.- Returns:
- the y position of this
Turtle
-
getHeading
public double getHeading()
Get the current heading of thisTurtle
.- Returns:
- the heading in degrees of this
Turtle
-
setHeading
public void setHeading(double heading)
Set the heading of thisTurtle
.- Parameters:
heading
- new heading in degrees for thisTurtle
-
right
public void right()
Turn thisTurtle
90 degrees clockwise.
-
left
public void left()
Turn thisTurtle
90 degrees counterclockwise.
-
turn
public void turn(double degrees)
Turn thisTurtle
by the given angle in degrees. Use positive angles to turn clockwise and negative angles to turn counterclockwise.- Parameters:
degrees
- the amount to turn thisTurtle
in degrees
-
turnToFace
public void turnToFace(Turtle turtle)
Turn thisTurtle
to face anotherTurtle
.- Parameters:
turtle
- theTurtle
to turn towards
-
turnToFace
public void turnToFace(double x, double y)
Turn thisTurtle
towards the given (x, y).- Parameters:
x
- the x to turn thisTurtle
towardsy
- the y to turn thisTurtle
towards
-
home
public void home()
Move thisTurtle
to the coordinates (0, 0) and give it the heading of 0 degrees.
-
moveTo
public void moveTo(double x, double y)
Move thisTurtle
to the given (x, y) location.- Parameters:
x
- the x-coordinate to move thisTurtle
toy
- the y-coordinate to move thisTurtle
to
-
forward
public void forward()
Move thisTurtle
foward one unit in the heading direction.
-
backward
public void backward()
Move thisTurtle
backward one unit.
-
backward
public void backward(double distance)
Move thisTurtle
backward the given number of units.- Parameters:
distance
- the distance to walk thisTurtle
backward
-
forward
public void forward(double distance)
Move thisTurtle
forward the given number of units in the heading direction. If the pen is down, then add twoVertex
objects and aLineSegment
object to the underlyingTurtle
.- Parameters:
distance
- the distance to walk thisTurtle
forward in the heading direction
-
move
public void move(double distance)
Same as the forward() method but without building aLineSegment
.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 thisTurtle
forward in the heading direction
-
resize
public void resize(double s)
Change the length of the step size by the factors
.This is part of "Turtle Geometry" as defined by Ronald Goldman.
- Parameters:
s
- scaling factor for the newstepSize
-
-