skulpt/skulpt — pull request #312 by bzwheeler (2014-11-18 01:51:15+00:00)
Title: Turtle suspensions

This is a complete overhaul of the turtle library, or 98% percent according to the git diff :smirk:

**New Features**
* ```write()``` now supports ```move``` and ```align``` as well as the tuplet form of ```font=("Arial", 30, "bold")```
* turning is animated (like the real python version)
* ```circle()``` now supports the ```steps``` argument
* ```degrees()``` is fully implemented
* ```color()``` ```pencolor()``` ```fillcolor()``` and ```bgcolor``` work like the real python version
* skewed coordinates systems work like the real python version (no skewing of the shapes)

Performance of the drawing should be fairly constant no matter how complex the drawing is and should not slow down over time.

Setup is slightly different in that the ```Sk.TurtleGraphics``` configuration object has changed and is no longer required.

Here is the new format of the configuration, **note** all properties are optional and the config shows the default values.
```javascript
Sk.TurtleGraphics = {
target : 'turtle' // should be a div in which you want the canvases to be created
, width : 400 // if set to 0 will auto-calculate based on target size
, height: 400 // if set to 0 will auto-calculate based on target size
, animate: true
};
```

The implementation uses suspensions so the next python statement will not be executed until the current animation has completed.

Once you have it up and running here is some fun code to try to get a feel for the improved performance.

```python
import turtle
import random

def randc():
return random.randint(0, 255)

def polygon(t, steps, angle, size):
for i in range(steps):
t.pencolor( randc(), randc(), randc() )
t.circle(size/4,180,20)
t.speed(0)
t.penup()
t.goto(0,0)
t.setheading(-i*angle)
t.pendown()
t.speed(10)

tina = turtle.Turtle()
tina.speed(10)
tina.tracer(20)
tina.width(20)
tina.ht()
polygon( tina, 10000, 10, 360 )
```