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

Similar documents
Lab 6: Energizer Turtles

1 Turtle Graphics Concepts

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

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

Reference Guide Playful Invention Company

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

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

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

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

Sketch Out the Design

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

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

Lab 7: Experimenting with Life and Death

Basic Commands and Training

AKC Rally More Advanced Signs

Lab 5: Bumper Turtles

A Guide to the TurtleGraphics Package for R

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

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

The Lost Treasures of Giza

Coding with Scratch - First Steps

Maze Game Maker Challenges. The Grid Coordinates

Positive training techniques

Coding with Scratch Popping balloons

TIGER KEY RING GET INVOLVED:

Steffen Mühlhäuser. SCHWARZER KATER Spielregel Rules

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

Naked Bunny Evolution

Name a Puppy change a life

You are not forced to use the colours I use! Do your own thing if you wish, or copy it exactly as it is it s totally up to you

CS108L Computer Science for All Module 7: Algorithms

RITA RABBIT AND HER NOSE TUBE

The Agility Coach Notebooks

OPERATION AND MAINTENANCE MANUAL

Sampling and Experimental Design David Ferris, noblestatman.com

SUBNOVICE OBJECTIVES. Successful completion of this class means that the following objectives were obtained:

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

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

Rosettes... Introduction...

GEOG 490/590 SPATIAL MODELING SPRING 2015 ASSIGNMENT 3: PATTERN-ORIENTED MODELING WITH AGENTS

Half Yearly Examination for Primary Schools Year 5 ENGLISH (Listening Comprehension) Time: 30 minutes. Teacher s copy

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

CALL LEAH. (Pauses to check phone again) I guess technically it hasn t been three days, because it was like 2 A.M. when I left, but still.

Grandparents U, 2018 Part 2

Professional Ultrasonic Dog Whistle Guide

Anja Wrede & Christoph Cantzler. The Cat s Meow

Lab 10: Color Sort Turtles not yet sorted by color

Finch Robot: snap level 4

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

How to Train Your Dog to Stay

THINKING OUTSIDE THE LITTERBOX: HELPING OUR COMMUNITY SOLVE CAT BEHAVIOR PROBLEMS. Amanda Kowalski, M.S., CPDT-KA Behavior Center Director

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

Alien Population: Game Notes

Step by step lead work training

Buried Treasures: Discovering wisdom from observing your dog. A journal by DogandDojo.com

The Hare and the Tortoise. 2. Why was the Tortoise smiling at the end of the race? He lost the race. He won the race.

AGILITY RIGHT FROM THE START

Discover the Path to Life with Your Dog. Beginner Obedience Manual 512-THE-DOGS

LEASH OFF GAME ON EMPOWER & SUPERCHARGE YOUR RELATIONSHIP

An Adventure in the Woods

Plating the PANAMAs of the Fourth Panama Carmine Narrow-Bar Stamps of the C.Z. Third Series

TRACKING BLUE PENGUINS ON WEST COAST BEACHES. Some handy hints to identify common tracks

Measure time using nonstandard units. (QT M 584)

3. $ rosrun turtlesim turtlesim_node (See the turtle with Blue Background leave terminal window running and view turtle)

WCHS Volunteer Dog Walkers (10am 12pm, 7 days a week)

Rules of the Game. Lab Report - on a separate sheet

THE FIVE COMMANDS EVERY DOG SHOULD KNOW

CONTENTS. Communication It Is All About You!... 21

Mini 4-H ANIMAL FRIENDS

Sample Course Layout 1

WOMEN S GYMNASTICS SPECIAL ORDER WITH SUBLIMATION PICTURE REQUEST FORM

SAMPLE PAGE. Snakes Express Lapbook. Any Age. A Journey Through Learning

Thank you for downloading the Study Guide to go along with the performance

Games! June Seven Mathematical Games. HtRaMTC Paul Zeitz,

Beginner s Guide to Competitive Obedience

SECTION 5.0 OPERATION OF THE NATIONAL GRADING SYSTEM

Introduction to Python Dictionaries

Puppy Agility Games, Part 2 By Anne Stocum, photos by Dianne Spring

Colour Codes & Cable Make Up

Design Guide. You can relax with a INSTALLATION QUALITY,CERTIFIED QTANK POLY RAINWATER TANKS. qtank.com.au

Nordic FS/HTM Rules. In general: HTM/FREESTYLE

Recursion with Turtles

The way to recognition of the Dutch Colour Homer

PET DOOR IMPORTANT! READ AND FOLLOW THESE INSTRUCTIONS CAREFULLY AND KEEP FOR FUTURE REFERENCE.

Study Buddy. Based on the book by Louise Yates. Table of Contents

Hare & Tortoise. Hare & Tortoise was first presented by Tutti Frutti, UK, in 2011

Package TurtleGraphics

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

UNIT 6 DESCRIBING DATA Lesson 1: Summarizing, Representing, and Interpreting Data on a Single Measurement Variable

EDUCATION PROGRAM WORKSHEETS

The collie pups, Star, Gwen, Nevis, and Shep, pushed their way to the front of the crowd gathered at the bottom of the hill. A hushed silence fell

Beginners Guide to Dog Shows

The Agility Coach Notebooks

tucker turtle puppet D4F4F186CFFB4B124D1E8F6FE09AB085 Tucker Turtle Puppet

Companion stories. For more such stories, visit us at.

Virtual Dog Program in Scratch. By Phil code-it.co.uk

The City School. Learn Create Program

BEGINNER I OBEDIENCE Week #1 Homework

Welcome to the case study for how I cured my dog s doorbell barking in just 21 days.

Animal Speeds Grades 7 12

Transcription:

Turtle Race! Introduction In this project you will use loops to create a racing turtle game and draw a race track. Step 1: Race track You re going to create a game with racing turtles. First they ll need a race track. Activity Checklist Open the blank Python template Trinket: jumpto.cc/python-new. Add the following code to draw a line using the turtle : 1

The turtle write function writes text to the screen. Try it: Now let s use the turtle to draw some track markings for the race. Now you need to fill in the numbers in between to create markings: Did you notice that your code is very repetitive? The only thing that changes is the number to write. There s a better way of doing this in Python. You can use a for loop. Update your code to use a for loop: Hmm, that only prints numbers up to 4. In Python range(5) returns five numbers, from 0 up to 4. To get it to also return 5 you ll need to use range(6) : 2

Now we can draw some track markings. The turtle starts at coordinates (0,0) in the middle of the screen. Move the turtle to the top left instead: Ah, you ll want to lift the pen up first! Instead of drawing a line horizontally, let s draw vertical lines to create a track: right(90) makes the turtle turn right 90 degrees (a right angle.) Moving forward(10) 3

before putting the pen down leaves a small gap between the number and the start of the line. After drawing the line you lift up the pen and go backward(160) the length of the line plus the gap. It looks neater if you centre the numbers: And you can speed up the turtle so it draws faster: Save Your Project Challenge: More lines Can you change your code so that the track lines go right across the screen? 4

If you want to make the turtle go even faster you can use speed(0). Step 2: Racing turtles Now for the fun bit. Let s add some racing turtles. It would be really boring if the turtles did the same thing every time so they will move a random number of steps each turn. The winner is the turtle that gets the furthest in 100 turns. Activity Checklist When you use commands like forward(20) you are using a single turtle. But you can create more turtles. Add the following code to the end of your script (but make sure it s not indented): The first line creates a turtle called ada. The next lines set the colour and shape of the turtle. Now it really looks like a turtle! Let s send the turtle to the starting line: 5

Now you need to make the turtle race by moving a random number of steps at a time. You ll need the randint function from the Python random library. Add this import line to the top of your script: The randint function returns a random integer (whole number) between the values chosen. The turtle will move forward 1, 2, 3, 4, or 5 steps at each turn. One turtle isn t much of a race! Let s add another one: 6

Note that the code for moving the blue turtle needs to be in the same for loop as the code for moving the red turtle so that they each make a move every turn. Save Your Project Challenge: Race time! Now you re ready to race. Pick a turtle and an opponent and see who wins. Can you add more turtles so you can race with more friends? Colours include: orange, purple, violet, tomato, turquoise, magenta and brown - or you can go to jumpto.cc/colours and pick any colour you like! 7

Save Your Project Challenge: Do a twirl Can you use a for turn in range(): loop to make each turtle do a 360 degree twirl after they get to the starting line? You ll need to make sure they are facing in the right direction at the start of the race! ada.right(36) will turn the red turtle right by 36 degrees. Hint: A full turn is 360 degrees. A turtle could turn right 10 degrees 36 times, or left 5 degrees 72 times, or any other numbers make 360! Challenge: Dashed lines Can you use a loop to make the track lines dashed instead of solid? Hint: Find the code that draws a straight line. Try using: for, forward(), penup() and pendown() 8

Save Your Project 9