Creating Turtle Geometry with IPython
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
ipyturtle First Nov 20, 2016
js First Nov 20, 2016
pic
.gitignore
LICENSE
MANIFEST.in
README.md First Nov 13, 2016
setup.cfg First Nov 20, 2016
setup.py

README.md

ipython-turtle-widget

Creating Turtle Graphics in IPython/Jupyter

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).

Install

To install use pip:

$ pip install ipyturtle
$ jupyter nbextension enable --py --sys-prefix ipyturtle

For a development installation (requires npm),

$ 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

Examples

The most examples are inspired by Harold Abelson, Andrea diSessa: Turtle Geometry, MIT Press 1986

Start

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.

First Steps

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)

Square

t.reset() #clear canvas and start again
def square(size):
    for i in range(4):
        t.forward(size)
        t.right(90)
square(20)

Triangel

t.reset()
def triangle():
    for i in range(3):
        t.forward(100)
        t.right(120)
triangle()

Circle

t = Turtle(fixed=False, width=120, height=120)

def circle():
    for i in range(360):
        t.forward(1)
        t.right(1)

t






circle()

Changelog

0.2.0 First published version

Sources

More about Creating Custom Widgets in IPython https://github.com/ipython/ipywidgets
A template Widget Project https://github.com/ipython/ipywidgets