Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

Creating Turtle Geometry in IPython (Jupyter Widget)

Project description

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
Widget Javascript not detected.  It may not be installed properly. Did you enable the widgetsnbextension? If not, then run "jupyter nbextension enable --py --sys-prefix widgetsnbextension"

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

Project details


Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
ipyturtle-0.2.0-py2.py3-none-any.whl (81.6 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Nov 13, 2016

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page