Turtle demo

Select the desired demo.
Note that the content is editable.

Simple demo

When you click on Run, Brython translates the Python code into Javascript, which is then being executed in a single thread. The end result of turtle module computations is the creation of an aminated scene that uses SVG. This scene is then added to the DOM so that it can be seen.

The first time you do this, Brython has to do extra work to translate the turtle module from Python into Javascript; subsequent runs will be faster.

As soon as a scene has been created, the Run button will be disabled and two new buttons will be enabled: one to clear everything so that the program could be modified and executed again, and the second which can be used to show the scene that was created as many times as desired, without requiring additional computation.

When you select another demonstration, everything will be cleared automatically without having to click on the Clear button.



from browser import document
import turtle
turtle.set_defaults(
    turtle_canvas_wrapper = document['turtle-div']
)
t = turtle.Turtle()

t.width(5)

for c in ['red', '#00ff00', '#fa0', 'rgb(0,0,200)']:
    t.color(c)
    t.forward(100)
    t.left(90)

# dot() and write() do not require the pen to be down
t.penup()
t.goto(-30, -100)
t.dot(40, 'rgba(255, 0, 0, 0.5')
t.goto(30, -100)
t.dot(40, 'rgba(0, 255, 0, 0.5')
t.goto(0, -70)
t.dot(40, 'rgba(0, 0, 255, 0.5')

t.goto(0, 125)
t.color('purple')
t.write("I love Brython!", font=("Arial", 20, "normal"))


turtle.done()