Struct turtle::Turtle
[−]
[src]
pub struct Turtle { /* fields omitted */ }
A turtle with a pen attached to its tail
Methods
impl Turtle
[src]
fn new() -> Turtle
[src]
Initialize a new Turtle instance
fn speed(&self) -> Speed
[src]
Returns the current speed of the turtle
fn position(&self) -> Point
[src]
Returns the turtle's current location (x, y)
fn heading(&self) -> Angle
[src]
Returns the turtle's current heading
Units are by default degrees, but can be set using the methods
Turtle::use_degrees
or
Turtle::use_radians
.
fn is_visible(&self) -> bool
[src]
Returns true if the turtle is visible
fn is_using_degrees(&self) -> bool
[src]
Returns true if Angle values will be interpreted as degrees
fn is_using_radians(&self) -> bool
[src]
Returns true if Angle values will be interpreted as radians
fn is_pen_down(&self) -> bool
[src]
Return true if pen is down, false if it’s up.
fn pen_size(&self) -> f64
[src]
Returns the size (thickness) of the pen
fn pen_color(&self) -> Color
[src]
Returns the color of the pen
fn background_color(&self) -> Color
[src]
Returns the color of the background
fn fill_color(&self) -> Color
[src]
Returns the current fill color
This will be used to fill the shape when begin_fill()
and end_fill()
are called.
fn begin_fill(&mut self)
[src]
Begin filling the shape drawn by the turtle's movements
fn end_fill(&mut self)
[src]
Stop filling the shape drawn by the turtle's movements
fn pen_down(&mut self)
[src]
Pull the pen down so that the turtle draws while moving
fn pen_up(&mut self)
[src]
Pick the pen up so that the turtle does not draw while moving
fn set_pen_size(&mut self, thickness: f64)
[src]
Sets the thickness of the pen to the given size
fn set_pen_color<C: Into<Color>>(&mut self, color: C)
[src]
Sets the color of the pen to the given color
fn set_background_color<C: Into<Color>>(&mut self, color: C)
[src]
Sets the color of the background to the given color
fn set_fill_color<C: Into<Color>>(&mut self, color: C)
[src]
Sets the fill color to the given color
Note: Only the fill color set before begin_fill()
is called will be used to fill
the shape.
fn set_speed<S: Into<Speed>>(&mut self, speed: S)
[src]
Set the turtle's movement speed to the given setting. This speed affects the animation of the turtle's movement and rotation.
This method's types make it so that it can be called in a number of different ways:
turtle.set_speed("normal"); turtle.set_speed("fast"); turtle.set_speed(2); turtle.set_speed(10); // Directly using a Speed variant works, but the methods above are usually more convenient. turtle.set_speed(Speed::Six);
If input is a number greater than 10 or smaller than 1,
speed is set to 0 (Speed::Instant
). Strings are converted as follows:
String | Value |
---|---|
"slowest" |
Speed::One |
"slow" |
Speed::Three |
"normal" |
Speed::Six |
"fast" |
Speed::Eight |
"fastest" |
Speed::Ten |
"instant" |
Speed::Instant |
Anything else will cause the program to panic!
at runtime.
Moving Instantly
A speed of zero (Speed::Instant
) results in no animation. The turtle moves instantly
and turns instantly. This is very useful for moving the turtle from its "home" position
before you start drawing. By setting the speed to instant, you don't have to wait for
the turtle to move into position.
Learning About Conversion Traits
Using this method is an excellent way to learn about conversion
traits From
and Into
. This method takes a generic type as its speed parameter. That type
is specified to implement the Into
trait for the type Speed
. That means that any type
that can be converted into a Speed
can be passed to this method.
We have implemented that trait for several types like strings and 32-bit integers so that
those values can be passed into this method.
Rather than calling this function and passing Speed::Six
directly, you can use just 6
.
Rust will then allow us to call .into()
as provided by the Into<Speed>
trait to get the
corresponding Speed
value.
You can pass in strings, 32-bit integers, and even Speed
enum variants because they all
implement the Into<Speed>
trait.
fn clear(&mut self)
[src]
Delete the turtle's drawings from the screen.
Do not move turtle. Position and heading of the turtle are not affected.
fn hide(&mut self)
[src]
Makes the turtle invisible. The shell will not be shown, but drawings will continue.
Useful for some complex drawings.
fn show(&mut self)
[src]
Makes the turtle visible.
fn use_degrees(&mut self)
[src]
Change the angle unit to degrees.
fn use_radians(&mut self)
[src]
Change the angle unit to radians.
fn forward(&mut self, distance: Distance)
[src]
Move the turtle forward by the given amount of distance
.
distance
is given in "pixels" which are like really small turtle steps.
distance
can be negative in which case the turtle can move backward
using this method.
fn backward(&mut self, distance: Distance)
[src]
Move the turtle backward by the given amount of distance
.
distance
is given in "pixels" which are like really small turtle steps.
distance
can be negative in which case the turtle can move forwards
using this method.
fn right(&mut self, angle: Angle)
[src]
Rotate the turtle right (clockwise) by the given angle.
Units are by default degrees, but can be set using the methods
Turtle::use_degrees
or
Turtle::use_radians
.
fn left(&mut self, angle: Angle)
[src]
Rotate the turtle left (counterclockwise) by the given angle.
Units are by default degrees, but can be set using the methods
Turtle::use_degrees
or
Turtle::use_radians
.
fn turn_towards(&mut self, target: Point)
[src]
Rotates the turtle to face the given coordinates. Coordinates are relative to the center of the window.
If the coordinates are the same as the turtle's current position, no rotation takes place. Always rotates the least amount necessary in order to face the given point.
UNSTABLE
This feature is currently unstable and completely buggy. Do not use it until it is fixed.
fn poll_event(&mut self) -> Option<Event>
[src]
Returns the next event (if any).
fn wait_for_click(&mut self)
[src]
Convenience function that waits for a click to occur before returning.
Useful for when you want your program to wait for the user to click before continuing so that it doesn't start right away.