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 voidbackward()Move thisTurtlebackward one unit.voidbackward(double distance)Move thisTurtlebackward the given number of units.voidforward()Move thisTurtlefoward one unit in the heading direction.voidforward(double distance)Move thisTurtleforward the given number of units in the heading direction.doublegetHeading()Get the current heading of thisTurtle.doublegetXPos()Get the current x position of thisTurtle.doublegetYPos()Get the current y position of thisTurtle.voidhome()Move thisTurtleto the coordinates (0, 0) and give it the heading of 0 degrees.booleanisPenDown()Check if thisTurtle's pen is down.voidleft()Turn thisTurtle90 degrees counterclockwise.voidmove(double distance)Same as the forward() method but without building aLineSegment.voidmoveTo(double x, double y)Move thisTurtleto the given (x, y) location.voidpenDown()Set thisTurtle's pen down.voidpenUp()Lift thisTurtle's pen up.voidresize(double s)Change the length of the step size by the factors.voidright()Turn thisTurtle90 degrees clockwise.voidsetHeading(double heading)Set the heading of thisTurtle.voidsetPenDown(boolean value)Set thisTurtle's penDown variable.StringtoString()For debugging.voidturn(double degrees)Turn thisTurtleby the given angle in degrees.voidturnToFace(double x, double y)Turn thisTurtletowards the given (x, y).voidturnToFace(Turtle turtle)Turn thisTurtleto face anotherTurtle.
-
-
-
Constructor Detail
-
Turtle
public Turtle(Model model)
- Parameters:
model- a reference to the {link Model} that thisTurtleis builing- Throws:
NullPointerException- ifmodelisnull
-
Turtle
public Turtle(Model model, String name)
- Parameters:
model- a reference to theModelthat thisTurtleis builingname- aStringthat is a name for thisTurtle- Throws:
NullPointerException- ifmodelisnullNullPointerException- ifnameisnull
-
Turtle
public Turtle(Model model, double z)
- Parameters:
model- a reference to theModelthat thisTurtleis builingz- the z-plane for thisTurtle- Throws:
NullPointerException- ifmodelisnull
-
Turtle
public Turtle(Model model, String name, double z)
- Parameters:
model- a reference to theModelthat thisTurtleis builingname- aStringthat is a name for thisTurtlez- the z-plane for thisTurtle- Throws:
NullPointerException- ifmodelisnullNullPointerException- ifnameisnull
-
Turtle
public Turtle(Model model, double xHome, double yHome, double z)
- Parameters:
model- a reference to theModelthat thisTurtleis builingxHome- the intial x-coordinate for thisTurtleyHome- the intial y-coordinate for thisTurtlez- the z-plane for thisTurtle- Throws:
NullPointerException- ifmodelisnull
-
Turtle
public Turtle(Model model, String name, double xHome, double yHome, double z)
- Parameters:
model- a reference to theModelthat thisTurtleis builingname- aStringthat is a name for thisTurtlexHome- the intial x-coordinate for thisTurtleyHome- the intial y-coordinate for thisTurtlez- the z-plane for thisTurtle- Throws:
NullPointerException- ifmodelisnullNullPointerException- ifnameisnull
-
-
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 thisTurtle90 degrees clockwise.
-
left
public void left()
Turn thisTurtle90 degrees counterclockwise.
-
turn
public void turn(double degrees)
Turn thisTurtleby the given angle in degrees. Use positive angles to turn clockwise and negative angles to turn counterclockwise.- Parameters:
degrees- the amount to turn thisTurtlein degrees
-
turnToFace
public void turnToFace(Turtle turtle)
Turn thisTurtleto face anotherTurtle.- Parameters:
turtle- theTurtleto turn towards
-
turnToFace
public void turnToFace(double x, double y)
Turn thisTurtletowards the given (x, y).- Parameters:
x- the x to turn thisTurtletowardsy- the y to turn thisTurtletowards
-
home
public void home()
Move thisTurtleto the coordinates (0, 0) and give it the heading of 0 degrees.
-
moveTo
public void moveTo(double x, double y)
Move thisTurtleto the given (x, y) location.- Parameters:
x- the x-coordinate to move thisTurtletoy- the y-coordinate to move thisTurtleto
-
forward
public void forward()
Move thisTurtlefoward one unit in the heading direction.
-
backward
public void backward()
Move thisTurtlebackward one unit.
-
backward
public void backward(double distance)
Move thisTurtlebackward the given number of units.- Parameters:
distance- the distance to walk thisTurtlebackward
-
forward
public void forward(double distance)
Move thisTurtleforward the given number of units in the heading direction. If the pen is down, then add twoVertexobjects and aLineSegmentobject to the underlyingTurtle.- Parameters:
distance- the distance to walk thisTurtleforward 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 thisTurtleforward 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
-
-