Although I know I can install ColabTurtle to use Turtle on a Colab Notebook, I cannot figure out how. Could someone please give me an example on how to run Turtle codes on Colab?
2 Answers
Here is an example notebook.
First, you need to install it.
!pip install ColabTurtle
Then import all functions and init it.
from ColabTurtle.Turtle import *
initializeTurtle()
Then call normal turtle commands, e.g.
forward(100)
right(90)
forward(100)
right(90)
forward(100)
You can see all supported commands in the code.
To supplement this excellent answer, if you want to namespace the module to avoid name clashes, you can use
import ColabTurtle.Turtle as t
t.initializeTurtle()
t.forward(30)
Note that the library doesn't implement the same API as Python's built-in turtle module. Run help(t)
to see the list of available methods on what appears to be a singleton turtle.