/* jquery */ /* jquery accordion style*/ /* jquery init */

8 January 2013

Raspberry Pi Python: Turtle Shapes

Exploring the interactive world of Turtle Graphics on your Raspberry Pi is easy with Python's 'turtle' module.

Here's a short Python program to create a pattern using coloured shapes.

from turtle import *

# set a shape and colour
shape("circle")
shapesize(5,1,2)
fillcolor("red")
pencolor("darkred")

penup()  # no drawing
goto(0, -100)

for i in range(72):
   forward(10)
   left(5)
   tilt(7.5)
   stamp()

exitonclick()

Create a new Geany file, enter the Python code, save it as turtle-shapes.py and execute the program. After you've seen it run modify the code to experiment with different shapes, fill colours and pen colours.

Visit my Raspberry Pi page for news, reviews, advice and tutorials.

No comments: