Skip to main content

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


Download files

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

Files for ipyturtle, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size ipyturtle-0.2.0-py2.py3-none-any.whl (81.6 kB) File type Wheel Python version py2.py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page