Struct turtle::Turtle [] [src]

pub struct Turtle { /* fields omitted */ }

A turtle with a pen attached to its tail

Methods

impl Turtle
[src]

[src]

Initialize a new Turtle instance

[src]

Returns the current speed of the turtle

[src]

Returns the turtle's current location (x, y)

[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.

[src]

Returns true if the turtle is visible

[src]

Returns true if Angle values will be interpreted as degrees

[src]

Returns true if Angle values will be interpreted as radians

[src]

Return true if pen is down, false if it’s up.

[src]

Returns the size (thickness) of the pen

[src]

Returns the color of the pen

[src]

Returns the color of the background

[src]

Returns the current fill color

This will be used to fill the shape when begin_fill() and end_fill() are called.

[src]

Begin filling the shape drawn by the turtle's movements

[src]

Stop filling the shape drawn by the turtle's movements

[src]

Pull the pen down so that the turtle draws while moving

[src]

Pick the pen up so that the turtle does not draw while moving

[src]

Sets the thickness of the pen to the given size

[src]

Sets the color of the pen to the given color

[src]

Sets the color of the background to the given color

[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.

[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.

[src]

Delete the turtle's drawings from the screen.

Do not move turtle. Position and heading of the turtle are not affected.

[src]

Makes the turtle invisible. The shell will not be shown, but drawings will continue.

Useful for some complex drawings.

[src]

Makes the turtle visible.

[src]

Change the angle unit to degrees.

[src]

Change the angle unit to radians.

[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.

[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.

[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.

[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.

[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.

[src]

Returns the next event (if any).

[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.