Draw on the page or use an extra window. under construction
If you like it, use it. If you have some suggestions, tell me (gkvoelkl@nelson-games.de).
$ pip install ipyturtle
$ jupyter nbextension enable --py --sys-prefix ipyturtle
$ git clone https://github.com/gkvoelkl/ipython-turtle-widget.git
$ cd ipython-turtle-widget
$ pip install -e .
$ jupyter nbextension install --py --symlink --sys-prefix ipyturtle
$ jupyter nbextension enable --py --sys-prefix ipyturtle
The most examples are inspired by Harold Abelson, Andrea diSessa: Turtle Geometry, MIT Press 1986
from ipyturtle import Turtle
t = Turtle()
t
The turtle is drawn on its own part of the screen.
Or integrate the turtle graphic into the page
t2 = Turtle(fixed=False, width=100, height=100)
t2
With width and height you can change the extension of the drawing canvas.
t.back(40)
t.forward(100)
t.position()
(0.0, 60.0)
t.right(90)
t.heading()
0
t.forward(150)
t.left(45)
t.back(100)
t.left(45)
t.penup()
t.forward(100)
t.reset() #clear canvas and start again
def square(size):
for i in range(4):
t.forward(size)
t.right(90)
square(20)
t.reset()
def triangle():
for i in range(3):
t.forward(100)
t.right(120)
triangle()
t = Turtle(fixed=False, width=120, height=120)
def circle():
for i in range(360):
t.forward(1)
t.right(1)
t
circle()
0.2.0 First published version
More about Creating Custom Widgets in IPython https://github.com/ipython/ipywidgets
A template Widget Project https://github.com/ipython/ipywidgets