speed
Category:Turtle
Slowing down the speed of the turtle while drawing allows us to see the execution of each command more easily.
Examples
Basic Example
// Draw a line slowly.
speed(1);
moveForward();
Example: Different Speeds
Draw a square with the turtle moving at increasingly faster speeds (10, 20, 30, 40, 50, 60, 70, 80, 90, 100).
// Draw a square with the turtle moving at increasingly faster speeds
// (10, 20, 30, 40, 50, 60, 70, 80, 90, 100).
textLabel("speed", "speed: 10");
for (var i = 1; i <= 10; i++) {
for (var j = 0; j < 4; j++) {
setText("speed", "speed: " + i * 10);
speed(i*10);
moveForward(100);
turnRight(90);
}
}

Syntax
speed(value);
Parameters
Name | Type | Required? | Description |
---|---|---|---|
value | number | The speed of the app's execution in the range of (0-100) |
Returns
No return value. Alters execution speed only.
Tips
- The app execution speed can also be set by the tortoise-to-hare slider bar at the top of the Debug Console. Using speed() in code is useful if you want your app to run at a specific speed. The tortoise-to-hare slider bar is not part of your program, but lets you set the execution speed in order to debug an app.
Found a bug in the documentation? Let us know at support@code.org.