1 / 8

Class 2 Introduction to turtle graphics

Class 2 Introduction to turtle graphics. Today’s Topics. First steps Turtle graphics Python modules Python help and documentation for and range def – creating a function. Computing is a social activity. If you’ve got a question, ask it (it’s part of computing culture)

omer
Download Presentation

Class 2 Introduction to turtle graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Class 2Introduction to turtle graphics

  2. Today’s Topics First steps • Turtle graphics • Python modules • Python help and documentation • for and range • def – creating a function

  3. Computing is a social activity • If you’ve got a question, ask it (it’s part of computing culture) • We’re working in pairs. It’s more fun, more real and more productive. • Use the online help system and tutorial • Use the textbook • Ask a TA or tutor

  4. Introduction to Turtle Graphics • Type ‘from turtle import *’ and press enter • This gives you access to the functions in Python’s turtle module • A module is a collection of functions • ‘*’ matches everything • Type: • pendown() and press enter • forward(100) and press enter • A new window pops up and a straight line will be drawn • Why are the pendown() parens empty? What is the ‘100’ in the parens?

  5. Introduction to Turtle Graphics • Some useful commands • forward(distance) • left(degrees) • right(degrees) • goto(xcoord, ycoord) • up() – (no drawing) • down() – (pen ‘down’ for drawing) • clear() • Look up the Turtle module in the Python docs • Python manuals > Global module index > Turtle (Tk)

  6. Practice Drawing Shapes • Draw the following shapes using forward(),left() or right() • Triangle, square or rectangle, pentagon, dodecagon • Challenge problem 1: Draw a set of squares rotated at different angles • Challenge problem 2: Draw a set of squares offset from each other (hint: use ‘up’) • Write down the sequence of Python statements you used before you exit (you’ll need them later)

  7. Write your own function • Use def to create your own function • Put this function definition is a file def square(size): forward(size) right(90) forward(size) right(90) forward(size) right(90) forward(size) right(90)

  8. The for loop • Try this >>> for i in 'cat': print(i) • Now try this >>> for i in range(3): print('cat') • Use for in range() to improve your square function

More Related