Python 3 Turtle graphics. Lecture 24 COMPSCI111/111G SS 2017

Similar documents
A Guide to the TurtleGraphics Package for R

Package TurtleGraphics

PYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s

1 Turtle Graphics Concepts

Fractal. Fractals. L- Systems 1/17/12

Recursion with Turtles

Code, Draw, and 3D-Print with Turtle Tina

In this project you will use loops to create a racing turtle game and draw a race track.

Writing Simple Procedures Drawing a Pentagon Copying a Procedure Commanding PenUp and PenDown Drawing a Broken Line...

Turtle Ballet: Simulating Parallel Turtles in a Nonparallel LOGO Version. Erich Neuwirth

Lecture 1: Turtle Graphics. the turtle and the crane and the swallow observe the time of their coming; Jeremiah 8:7

Recursion with Turtles

Grandparents U, 2018 Part 2

RUBBER NINJAS MODDING TUTORIAL

Workbook. Version 3. Created by G. Mullin and D. Carty

by Jennifer Oxley and Billy Aronson

6. 1 Leaping Lizards!

Scratch Lesson Plan. Part One: Structure. Part Two: Movement

Reference Guide Playful Invention Company

Help the Scratch mascot avoid the space junk and return safely back to Earth! Start a new Scratch project. You can find the online Scratch editor at

Bluefang. All-In-One Smart Phone Controlled Super Collar. Instruction Manual. US and International Patents Pending

Coding with Scratch Popping balloons

CS108L Computer Science for All Module 7: Algorithms

6Measurement. What you will learn. Australian curriculum. Chapter 6B 6C 6D 6H 6I

Biology 164 Laboratory

Sketch Out the Design

Hello Scratch! by Gabriel Ford, Sadie Ford, and Melissa Ford. Sample Chapter 3. Copyright 2018 Manning Publications

The City School. Learn Create Program

Quick Setup Guide Model 5134G

Finch Robot: snap level 4

Geometry from Scratch

All Dogs Parkour Exercises (Interactions) updated to October 6, 2018

How to draw. pets & farm animals. with basic shapes!

Finch Robot: snap levels 1-3

~~~***~~~ A Book For Young Programmers On Scratch. ~~~***~~~

Coding with Scratch - First Steps

The FCI Initiative for Young Dog Lovers Worldwide. Basic recomendations ORGANIZING YOUTH ACTIVITIES FOR CYNOLOGICAL VENUES.

Lab 10: Color Sort Turtles not yet sorted by color

Scratch Programming Lesson One: Create an Scratch Animation

International Play Concepts B.V. PO box 29 NL-3890 AA Zeewolde The Netherlands. T: +31(0) E: W:

Rally Signs & Descriptions

2. FINISH - Indicates the end of the course - timing stops. 1. START - Indicates the beginning of the course.

82½" x 82½" Maison De Charlotte Multiple 3 patterns in one. Sizes. 3 patterns in one

StarLogo Complete Command List (Edited and reformatted by Nicholas Gessler, 6 June 2001.)

RALLY-O Sign Commands

Measure time using nonstandard units. (QT M 584)

Scentwork UK. Guidelines for Level 1 Trials

Lab 7. Evolution Lab. Name: General Introduction:

Please initial and date as your child has completely mastered reading each column.

Simrad ITI Trawl monitoring system

Scratch. To do this, you re going to need to have Scratch!

The Effect of Phase Shifts in the Day-Night Cycle on Pigeon Homing at Distances of Less than One Mile

AKC Rally More Advanced Signs

Biol 160: Lab 7. Modeling Evolution

Scentwork UK. Guidelines for Level 2 Trials

Genetics Lab #4: Review of Mendelian Genetics

Official Rules & Regulations

Our class had 2 incubators full of eggs. On day 21, our chicks began to hatch. In incubator #1, 1/3 of the eggs hatched. There were 2 chicks.

09/17/18 1 Turtlesim Cheat Sheet pages (PG) in book ROS Robotics By Example 2nd, Fairchild and Harman

Lab 7: Experimenting with Life and Death

Cross wheelchairs. Cross wheelchairs.

1.1 Brutus Bites Back

Introduction. Trawl Gear description (fish & shrimp) Introduction. Introduction 4/4/2011. Fish & invertebrates

Code Documentation MFA (Movable Finite Automata) Eric Klemchak CS391/CS392

Kentucky Academic Standards

Neck. Forelimbs. ,pine. Hindlimbs. PropriocepAion. Area. -ick CiAh each exercise yob do! Mark with an L (left side) or R (right side)!

COMP Intro to Logic for Computer Scientists. Lecture 9

CHOOSING YOUR REPTILE LIGHTING AND HEATING

Half-Lives of Antibiotics

Level 2 Signs with Explanations A4.indd 1 09/04/ :35:50

RALLY SIGNS AND DESCRIPTIONS. The principal parts of the exercises are boldface and underlined.

Genetics Lab #4: Review of Mendelian Genetics

MOORHEAD. Logo Usage Guide. City of Moorhead

Scentwork UK. Guidelines for Level 4 Trials

EVOLUTION IN ACTION: GRAPHING AND STATISTICS

Econometric Analysis Dr. Sobel

Lab 5: Bumper Turtles

Introduction to Python Dictionaries

The Cat Sentence-Building Exercise 1

INSTALLATION INSTRUCTIONS

Activity 21. Teachers notes. Learning objective. Resources. Cross-curricular links. Activity. Extension

Graphics libraries, PCS Symbols, Animations and Clicker 5

Chinese New Year ACTIVITY 1: Animals (all levels) - WORKSHEET 1

The Lost Treasures of Giza

About the Show. The Characters

Objective Learn about the specific hazards on a working farm and how to recognise the various safety signs used.

Pet Notes and Appointment Notes

The Shape Of My Turkey Packet

1.1 Brutus Bites Back A Develop Understanding Task

Mathematics Reading Writing & Language

Genes What are they good for? STUDENT HANDOUT. Module 4

Yoga Puppies 2013 Mini 7x7 By Browntrout Publishers READ ONLINE

Scentwork UK. Guidelines for Level 4 Trials

BOLT AWARDS. Ann Masters, Copywriter AWARDS Treats For Good Behavior

ONCE DAILY GENTAMICIN DOSING AND MONITORING IN ADULTS POLICY QUESTIONS AND ANSWERS

RALLY SIGNS Descriptions and Symbols for Rally Signs Exercises that may be used in Novice, Advanced and Excellent Classes

It s the sport dogs put their paw up for!

Overview of Online Record Keeping

mouse shapes F4F79BABB796794A55EFF1B Mouse Shapes 1 / 6

FPGA-based Emotional Behavior Design for Pet Robot

Transcription:

Python 3 Turtle graphics Lecture 24 COMPSCI111/111G SS 2017

Today s lecture The Turtle graphics package Brief history Basic commands Drawing shapes on screen

Logo and Turtle graphics In 1967, Seymour Papert and Wally Feurzeig created an interpretive programming language called Logo. Papert added commands to Logo so that he could control a turtle robot, which drew shaped on paper, from his computer Turtle graphics is now part of Python Using the Turtle involves instructing the turtle to move on the screen and draw lines to create the desired shape

The Turtle package Some functions are part of Python s core libraries, in other words they are built-in print() input() float() Other functions need to be imported into your Python program The turtle module needs to be imported at the start of any Python program that uses it: import turtle

Basic Turtle commands There are four basic turtle commands turtle.forward(x) Moves turtle forward in direction it is facing by x steps turtle.back(x) Moves turtle backward from its facing direction by x steps turtle.left(x) Turns the turtle x degrees counterclockwise turtle.right(x) Turns the turtle x degrees clockwise

Turtle example Using the Python interpreter in IDLE to demonstrate how to use Turtle graphics First, import the turtle package >>> import turtle >>>

Turtle example We are going to draw a right-angled triangle 90 Important information: The turtle appears as an icon Initial position: (0, 0) Initial direction: East (0 ) Colour: black Line width: 1 pixel Pen: down (ready to draw) x-axis (0,0) 180 0 270 y-axis

Algorithm draw a line Turn 90 degrees left (anti-clockwise) draw a line Turn 135 degrees left (anti-clockwise) draw a line

Turtle example Step 1: Draw a line >>> import turtle >>> >>> turtle.forward(200) >>> 1. Draw a line

Turtle example 90degree Initial direction: 0 Note how the turtle is now facing upward after being turned 90 degrees left >>> import turtle >>> >>> turtle.forward(200) >>> turtle.left(90) >>>

Turtle example Step 3: draw a line >>> import turtle >>> >>> turtle.forward(200) >>> turtle.left(90) >>> turtle.forward(200) >>>

Turtle example current direction 135degree Step 4: turn 135 degree left (anti-clockwise) >>> import turtle >>> >>> turtle.forward(200) >>> turtle.left(90) >>> turtle.forward(200) >>> turtle.left(135) >>>

Turtle example Working out the length of the longest side using the Pythagoras formula >>> import turtle >>> >>> turtle.forward(200) >>> turtle.left(90) >>> turtle.forward(200) >>> turtle.left(135) >>> c = ((200**2)+(200**2))**0.5 #around 283 steps

Turtle example Step 6: draw a line The finished image >>> import turtle >>> >>> turtle.forward(200) >>> turtle.left(90) >>> turtle.forward(200) >>> turtle.left(135) >>> c = ((200**2)+(200**2))**0.5) >>> turtle.forward(c)

Turtle example We can use loops when drawing shapes using Turtle graphics Write a program that will draw a square using a loop Draw a line Turn 90 degree left X 4 times

Turtle example We can use loops when drawing shapes using Turtle graphics Write a program that will draw a square using a loop import turtle count = 0 while count < 4: turtle.forward(200) turtle.left(90) count = count + 1

Exercise 1 TRY IT OUT! Write a Python program that draws a rectangle. The long sides must be 300 steps long and the short sides must be 150 steps long Draw a long line Turn 90 degree left Draw a short line Turn 90 degree left Draw a long line Turn 90 degree left Draw a short line Turn 90 degree left

Turtle example Write a program that will draw a circle Steps: Draw a short line (2 pixels) Turn 1 degree Repeat the above steps 360 times

Turtle example Write a program that will draw a circle import turtle count = 0 while(count < 360): turtle.forward(2) turtle.left(1) count = count + 1 print("finished!")

Question Consider the following program: import turtle count = 0 length = 100 while count < 4: turtle.forward(length) turtle.left(90) count = count + 1 length = length - 10 Which of the following pictures demonstrates the output generated by the program above?

Exercise 2 Go to: pwlive.pw How to draw a star? How many steps do you need? What is the size/length for each step? What is the turning angle for each step?

Exercise 3 TRY IT OUT! Draw the shape that is produced by the following Python program: import turtle count = 0 while(count < 180): turtle.forward(2) turtle.right(1) count = count + 1 turtle.right(45) turtle.forward(300) turtle.left(90) turtle.back(150) turtle.right(45) turtle.back(250)

Exercise 4 TRY IT OUT! Draw the shape that is produced by the following Python program: import turtle big_line = 100 little_line = 50 angle = 90 turtle.left(angle) turtle.forward(big_line) count = 0 while count < 4: turtle.right(angle//2) if count!= 3: turtle.forward(little_line) else: turtle.forward(big_line) count = count + 1 turtle.right(90) turtle.forward(130)

Summary The Turtle package must be imported into every Python program that uses it The Turtle has four basic commands; forward, back, left and right