Skip to content

Turtle ​

Instance declaration ​

When you add a Turtle block to the workspace, the following instance declaration is automatically inserted into the Python code:

python
turtle = Turtle(0)
# When there are multiple instances
turtle_1 = Turtle(1)

Parameters ​

NameKindDescriptionRange / TypeDefault
indexDropdown optionInstance number (starting from 0)Integer 0 or greater0

Set wheel speed ​

Determines the wheel speed. The speed ranges from -100 to 100.

set_wheel_speed

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionWheel to controlleft, right, both-
speedInput (block)Wheel speedInteger -100 to 100, 0: stop-

Python ​

python
turtle = Turtle(0)

turtle.set_wheel_speed('both', 50)

Move a distance ​

Sets the distance to move.
If the wheel speed has not been set, it does not move.
If the distance is 0, it keeps moving according to the current wheel speed.
If wait is checked, execution waits until the movement is complete.

move_distance

Parameters ​

NameKindDescriptionRange / TypeDefault
dataInput (block)Distance to moveReal number 0 or greater-
unitDropdown optionDistance unitcm, mm, inchcm
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

python
turtle = Turtle(0)

turtle.move_distance(50, 'cm', wait=True)

Move for a time ​

Moves for the specified time at the current wheel speed.
If the wheel speed has not been set, it moves forward at the default speed.
If wait is checked, execution waits until the movement is complete.

move_time

Parameters ​

NameKindDescriptionRange / TypeDefault
dataInput (block)Time to move (seconds)Real number 0 or greater-
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

python
turtle = Turtle(0)

# wait = TRUE
turtle.move_time(5, wait=True)
# wait = FALSE
turtle.move_time(0.5, wait=False)

Turn in place ​

Sets the direction and angle to rotate in place.
If wait is checked, execution waits until the rotation is complete.

turn_degree

Parameters ​

NameKindDescriptionRange / TypeDefault
directionDropdown optionDirection of rotationleft, right-
dataInput (block)Angle of rotation (degrees)Real number 0 or greater-
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

python
turtle = Turtle(0)

turtle.turn_degree('left', 90, wait=True)

Change wheel speed ​

Changes the wheel speed of Turtle.
The new wheel speed is the current wheel speed plus the speed you enter.

change_speed

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionWheel to controlleft, right, both-
speedInput (block)Amount of speed changeInteger -200 to 200-

Python ​

python
turtle = Turtle(0)

turtle.change_wheel_speed('both', 10)

Stop ​

Stops the movement of Turtle.

stop

Parameters ​

(none)

Python ​

python
turtle = Turtle(0)

turtle.stop()

Is the wheel moving? ​

Returns true if the wheel is moving, and false if it is stopped.

wheel_moving

Parameters ​

(none)

Python ​

python
turtle = Turtle(0)

turtle.wheel_moving()

Pivot around a wheel ​

Sets the pivot point, direction, and angle of rotation.
If wait is checked, execution waits until the rotation is complete.

pivot

Parameters ​

NameKindDescriptionRange / TypeDefault
baseDropdown optionWheel to pivot aroundleft wheel (left_wheel), right wheel (right_wheel)-
directionDropdown optionDirection of rotationforward, backward-
dataInput (block)Angle of rotation (degrees)Real number 0 or greater-
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

python
turtle = Turtle(0)

turtle.pivot('left_wheel', 'forward', 90, wait=True)

Draw a circle ​

When drawing a circle with the pen, sets the direction, radius, and angle of rotation.
If wait is checked, execution waits until the rotation is complete.

pivot_circle

Parameters ​

NameKindDescriptionRange / TypeDefault
directionDropdown optionDirection of rotationleft forward (left_forward), left backward (left_backward), right forward (right_forward), right backward (right_backward)-
degreeInput (block)Angle of rotation (degrees)Real number 0 or greater-
radiusInput (block)Radius of rotationReal number 0 or greater-
unitDropdown optionRadius unitcm, mm, inchcm
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

python
turtle = Turtle(0)

turtle.pivot_circle('left_forward', 90, 1, 'cm', wait=True)

Trace a line with the sensor ​

Uses the color sensor on the bottom to move along a line of a particular color.

trace_line

Parameters ​

NameKindDescriptionRange / TypeDefault
lineDropdown optionColor of the line to traceblack, red, green, blue, anyblack

Python ​

python
turtle = Turtle(0)

turtle.trace_line('black')

Trace a line until a particular color ​

Uses the color sensor on the bottom to trace a line of color A until it meets color B.

trace_line_until_color

Parameters ​

NameKindDescriptionRange / TypeDefault
lineDropdown optionColor of the line to traceblack, red, green, blue, any-
colorDropdown optionColor to stop atblack, red, green, cyan, blue, magenta, any-
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

python
turtle = Turtle(0)

turtle.trace_line_until_color('black', 'red', wait=True)

Move through an intersection and stop at the next one ​

Turtle moves in the specified direction at an intersection, then keeps moving until it meets the next intersection.
If wait is checked, execution waits until the movement is complete.

intersection

Parameters ​

NameKindDescriptionRange / TypeDefault
directionDropdown optionDirection to take at the intersectionforward, left, right, u-turn (uturn)-
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

python
turtle = Turtle(0)

turtle.trace_intersection('left', wait=True)

Set line trace speed ​

Sets the line trace speed. The speed ranges from 1 to 10.

set_trace_speed

Parameters ​

NameKindDescriptionRange / TypeDefault
dataInput (block)Line trace speedInteger 1 to 10-

Python ​

python
turtle = Turtle(0)

turtle.set_trace_speed(5)

Set line trace gain ​

Sets the amount by which the line trace direction changes. The gain ranges from 1 to 10.

set_trace_gain

Parameters ​

NameKindDescriptionRange / TypeDefault
dataInput (block)Amount of direction changeInteger 1 to 10-

Python ​

python
turtle = Turtle(0)

turtle.set_trace_gain(5)

Stop line tracing ​

Ends the line tracing function of Turtle.

stop_trace

Parameters ​

(none)

Python ​

python
turtle = Turtle(0)

turtle.stop_trace()

Set LED color ​

Sets the head LED color of Turtle.
When you pick a color from the color palette, it is converted to a color name (an English string) for the call. (The generated code uses a color name, not R, G, B numeric values.)

set_led_color

Parameters ​

NameKindDescriptionRange / TypeDefault
colorColorPick from the color palette → converted to a color name (English)Color names: 'black', 'red', 'yellow', 'green', 'cyan', 'blue', 'magenta', 'white'-

Python ​

python
turtle = Turtle(0)

turtle.set_led_color('red')

Set LED color with a Color category block ​

Takes the output of a Color category block ([R, G, B]) as input and sets the head LED color.

set_led_color_with_block

Parameters ​

NameKindDescriptionRange / TypeDefault
dataInput (color)A Color category block or an [R, G, B] array[0~255, 0~255, 0~255]-

Python ​

python
turtle = Turtle(0)

turtle.set_led_color(*Utils.color('red'))

Change LED color by RGB ​

Adds the R, G, and B amounts you enter to the current head LED color to set a new color.

change_by_rgb

Parameters ​

NameKindDescriptionRange / TypeDefault
rInput (field)Amount of red changeInteger -255 to 2550
gInput (field)Amount of green changeInteger -255 to 2550
bInput (field)Amount of blue changeInteger -255 to 2550

Python ​

python
turtle = Turtle(0)

turtle.change_led_color(10, 0, 0)

Turn off LED ​

Removes the head LED color.

turn_off

Parameters ​

(none)

Python ​

python
turtle = Turtle(0)

turtle.turn_off()

Set sound buzz ​

Sets the buzzer sound of Turtle to the specified frequency.

sound_buzz

Parameters ​

NameKindDescriptionRange / TypeDefault
hzInput (block)Frequency (Hz)Real number 0 to 6553.5-

Python ​

python
turtle = Turtle(0)

turtle.sound_buzz(440)

Play a note ​

Turtle plays the specified note.

sound_note

Parameters ​

NameKindDescriptionRange / TypeDefault
noteDropdown optionNoteDo (C), Do# (C#), Re (D), Re# (D#), Mi (E), Fa (F), Fa# (F#), Sol (G), Sol# (G#), La (A), La# (A#), Si (B)-
octaveDropdown optionOctave1, 2, 3, 4, 5, 6, 74

Python ​

python
turtle = Turtle(0)

turtle.sound_note('D', 5)

Play a sound clip ​

Turtle plays a particular sound clip.

sound_clip

Parameters ​

NameKindDescriptionRange / TypeDefault
clipDropdown optionSound clip name'mute', 'beep', 'siren', 'engine', 'robot', 'march', 'birthday', 'dibidibidip', 'good_job', and so on-
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

python
turtle = Turtle(0)

turtle.sound_clip('siren', wait=True)

Sound off ​

Turns off the sound of Turtle.

sound_off

Parameters ​

(none)

Python ​

python
turtle = Turtle(0)

turtle.sound_off()

Is a sound playing? ​

Returns true if a sound is playing, and false if it is not.

sound_playing

Parameters ​

(none)

Python ​

python
turtle = Turtle(0)

turtle.sound_playing()

Wheel speed value ​

The speed of a particular wheel

wheel_speed

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionWheel to readleft, right-

Python ​

python
turtle = Turtle(0)

turtle.wheel_speed('left')

Floor color sensor value ​

The value of the color sensor on the bottom

floor

Parameters ​

(none)

Python ​

python
turtle = Turtle(0)

turtle.floor()

Card color name value ​

The name of the card color read through the color sensor on the bottom

card_color

Parameters ​

(none)

Python ​

python
turtle = Turtle(0)

turtle.card_color()

Card color pattern value ​

The pattern of the card colors read through the color sensor on the bottom

card_pattern

Parameters ​

(none)

Python ​

python
turtle = Turtle(0)

turtle.card_pattern()

Gravitational acceleration value ​

The gravitational acceleration value along a particular axis

acceleration

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionAxis to measurex, y, z-

Python ​

python
turtle = Turtle(0)

turtle.acceleration('x')

Temperature sensor value ​

The temperature sensor value

temperature

Parameters ​

(none)

Python ​

python
turtle = Turtle(0)

turtle.temperature()

Signal strength value ​

The signal strength

signal_strength

Parameters ​

(none)

Python ​

python
turtle = Turtle(0)

turtle.signal_strength()

Battery voltage ​

The battery voltage

battery

Parameters ​

(none)

Python ​

python
turtle = Turtle(0)

turtle.battery()

Is it touching a particular color? ​

Measures through the Turtle color sensor whether it is touching the specified color and returns true (True) / false (False).

color_read

Parameters ​

NameKindDescriptionRange / TypeDefault
colorDropdown optionColor nameunknown, red, yellow, green, cyan, blue, magenta, white-

Python ​

python
turtle = Turtle(0)

turtle.is_card_color('red')

Is the card color pattern ~ ? ​

Returns whether the pattern of the card colors recognized by the color sensor matches, as true (True) / false (False).

pattern_read

Parameters ​

NameKindDescriptionRange / TypeDefault
patternDropdown optionCard pattern name'red_yellow', 'red_green', 'blue_red'-

Python ​

python
turtle = Turtle(0)

turtle.is_card_pattern('red_yellow')

Back button state ​

Whether the button on the back is pressed or has been clicked

button

Parameters ​

NameKindDescriptionRange / TypeDefault
eventDropdown optionKind of button statepressed, click, long click (long_click)-

Python ​

python
turtle = Turtle(0)

turtle.button('pressed')

Whether the state has changed ​

Whether the state of the robot has changed

state_change

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionKind of state0 to 5 (see the table below)-
unitCondition
0acceleration('x') > 50
1acceleration('x') < -50
2acceleration('y') > 50
3acceleration('y') < -50
4acceleration('z') > 0
5acceleration('z') < -30

Python ​

python
turtle = Turtle(0)

# unit = 0
turtle.acceleration('x') > 50