Presentation is loading. Please wait.

Presentation is loading. Please wait.

Python Turtle Graphics

Similar presentations


Presentation on theme: "Python Turtle Graphics"— Presentation transcript:

1 Python Turtle Graphics
ASFA CS Principles

2 A first Object: Logo Turtle
Dr. Seymour Papert at MIT invented the Turtle as a graphical and mathematical object to think with for the children’s programming language, Logo (1966)

3 Robot Turtles Children programmed robot turtles to draw pictures

4 A turtle is an object. Every turtle understands the same methods. Every turtle has the same fields or instance variables. Heading, body color, pen color, X and Y position. Yet each turtle can have its own values for these fields. Many modern programming languages, such as Python, continue to use turtles for drawing

5 Think of a turtle crawling on a piece of paper, with a pen tied to its tail
Sheet of paper is a window on a display screen Position specified with (x, y) coordinates Cartesian coordinate system, with origin (0, 0) at the center of a window

6 Imagine a turtle starting at (0, 0)
Give it the command turtle.forward(15), and it moves (on-screen) 15 pixels in the direction it is facing, drawing a line as it moves. Give it the command turtle.left(25), and it rotates in-place 25 degrees counter-clockwise.

7 Some Examples of Turtle Programs
A forest scene created with turtles A Recursive Turtle Drawing Program

8 Some Key Methods from turtle import * # pen/turtle starts at the center (x=0, y=0) of the turtle display area shape(“turtle”) color("green") # pen up, don't draw up() # centers the circle goto(0,-50) # pen down, draw down() # radius=50 center is 50 radius units above the turtle circle(50) # center the turtle again goto(0,0) tur2.py

9 Turtle drawing with repetition
from turtle import * def star(): color('red', 'purple') colormode(255) begin_fill() for i in range(36): pencolor(3*i + 100, 0 , 5*i) forward(200) left(85) forward(10) left(45) forward(40) left(-90) end_fill() setpos(100,45) color("white","yellow") shape("turtle") star() spyro.py

10 Recursive Drawing Algorithms
Recursive Algorithms are used to create fractals

11 Documentation available explaining methods available
If you have trouble getting the docs from Python, you can go to

12 Turtle library contains many methods

13 Click on method you want to see

14 Method usage documentation and examples

15 Endless Artistic Possibilities

16 What can you create?

17 Assignment Explore the documentation
Design and program a turtle drawing a picture Must include: At least 4 colors At least 4 shapes A filled object Looping Show me the drawing creation your program to me after checked off Make a multi-turtle program if you are done

18


Download ppt "Python Turtle Graphics"

Similar presentations


Ads by Google