Recursion with Turtles

Similar documents
Recursion with Turtles

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

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

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

1 Turtle Graphics Concepts

Centennial Museum Lesson Plan

BEGINNER NOVICE OBEDIENCE. Beginner Novice Class ---replacing the old Sub Novice A, B, and C1 & C2.

Agriculture: Animal Health Technology. o Work Experience, General. o Open Entry/Exit. Distance (Hybrid Online) for online supported courses

PRACTICE MANAGEMENT. Steven D. Garner, DVM, DABVP

Revolution is an easy-to-administer, all-in-one flea treatment for cats and dogs that simply works inside and out for a full month.

Agriculture: Animal Health Technology. o Work Experience, General. o Open Entry/Exit. Distance (Hybrid Online) for online supported courses

The Effect of Various Types of Brooding on Growth and Feed Consumption of Chickens During the First 18 Days After Hatch

Package TurtleGraphics

Why talk about this now?

GUIDE TO THE PROFESSIONAL PRACTICE STANDARD

Lesson 11. Lesson Outline: Form and Function of the Axial Skeleton o o o

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

MANAGEMENT PRACTICES (Handling)

~~ Always check PAWS for the most current due dates & times! ~~

IELTS SPEAKING: SAMPLE ANSWERS Part 2 & 3

The Rookery FIRST EDITION! Inside

Stress-free Stockmanship

TESTING APPLICATION CHANGES WITH IMPRIVATA ONESIGN

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

5.1. What do we need to know before we start planning a canine rabies control programme?

Manual. Compiled by. Leslie Bergh & Tim Pauw. Copyright reserved by BenguelaSoft CC. Version

BACS kitten information session 4/1/13

Manual. Compiled by. Leslie Bergh & Tim Pauw. Copyright reserved by BenguelaSoft CC. Version

Chimera: Usability Test

4-H & FFA JUNIOR LIVESTOCK AUCTION Saturday, August 11, 2018, 11 a.m.

SOME PREY PREFERENCE FACTORS FOR A L. SNYDER

Early Language and Intercultural Acquisition Studies Multilateral EU-Comenius-Project E L I A S

CITY OF NAPERVILLE Transportation, Engineering & Development (TED) Business Group

Agriculture: Animal Science-General Subjects. o Work Experience, General. o Open Entry/Exit. Distance (Hybrid Online) for online supported courses

Understanding Puppy Nipping Physical exercise Puppy playtime Human playtime Chew deterrents Shunning/Freezing/Yelping Techniques

VBS 2016 Adult-2 Hour Base Conference

Neonatal Phase (1-2 weeks)

Reference Guide Playful Invention Company

ENGLISH HOMEWORK 2. How high can you jump? If you are like most people, you can probably jump one or two feet high.

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

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

VBS 2018 ADULT VBS EXTRAS CONFERENCE PLAN (1 HOUR)

Activity 7: A Journey Through Time

COAT COLOURS DESCRIPTION

Defini:ons of Plagiarism

APPLICATION FOR LIVE ANIMAL USE IN TEACHING AT COASTAL ALABAMA COMMUNITY COLLEGE

Coordinators. or F For Mary enjoys math, for it is challenging. RESULT/CAUSE

VBS FOLLOW UP CONFERENCE PLAN (1 HOUR)

OAVT Newsletter Dedicated to promoting Veterinary Technicians and quality animal healthcare through: Education, Legislation and High Ethical Standards

Prevalence and risk factors for limb and claw lesions and lameness in young sows

THE HUMANE SOCIETY OF THE UNITED STATES Cape Wildlife Center 4011 Main St. (Route 6A), Barnstable, MA Phone: (508) Fax: (508)

A Guide to the TurtleGraphics Package for R

Pet Adoption Application

Hastings Grade 1 Spring 3/09. GRADE 1 SPRING NATURE WALK What Animals Need to Survive

Half-Lives of Antibiotics

Gulval School Pets in School Policy. June 2016

SMALL ANIMAL ORDINANCE Ordinance Amendments Section V.V Keeping of Animals

Machine Learning.! A completely different way to have an. agent acquire the appropriate abilities to solve a particular goal is via machine learning.

FEDERATION CYNOLOGIQUE INTERNATIONALE (AISBL)

Animal ID Entry 4HOnline HelpSheet

Infection control Training Program

Regulating breeding and sales of dogs to minimize dog abandonment, animal abuse and over-breeding

ANIMAL CARE PROTOCOL SUMMARY Greyhound Friends, Inc., Hopkinton, MA August, 2018

A Pan-Canadian Framework on Antimicrobial Resistance. Presentation to the National Farmed Animal Health and Welfare Council November 30, 2016

PET FOOD DISTRIBUTION PROGRAM

2018 Sponsorship Opportunities. Humane Heroes Opportunities. Event-specific Opportunities

Lab 10: Color Sort Turtles not yet sorted by color

Volunteer Application

Hind Leg Paralysis. By Suz Enyedy

BOWMAN GRADE 1 WINTER NATURE WALK Animals and What They Need to Survive

The Global Momentum for AMR Moving from Knowledge to Action

A STUDY OF CROSSBREEDING SHEEP K. P. MILLER AND D. L. DAILEY

ANOPHELES SUNDAICUS IN SINGAPORE

ANIMAL EMBASSY PROGRAM ANIMAL GUIDELINES

LYME DISEASE THE BIG PICTURE

Vet. Assisting 1, Semester 2 Course Review

The Beef Herd Health Management Calendar

All red dogs should have a training plan: READ IT BEFORE YOU TAKE OUT THE DOG.

Animal ID Entry 4HOnline HelpSheet

VBS 2018 ADULT VBS BASE CONFERENCE PLAN (2 HOURS)

Honors English: Summer Break Reading Requirement

4-H Livestock Quality Assurance Program NPQ

MEDICAL CENTER WIDE POLICY AND PROCEDURE MANUAL Fontana & Ontario Medical Centers Policies & Procedures


Labour Providers Survey 2016 A seasonal labour monitoring tool for Horticulture and Potatoes

Austin, TX. Getting to No Kill. from the perspective of Austin Pets Alive! Ellen Jefferson, DVM Executive Director Austin Pets Alive!

Grandparents U, 2018 Part 2

C.A.R.E. Pet Adoption Application & Contract

1 '~; c\ 1.Introduction

Federal Junior Duck Stamp Program Conservation Through the Arts

HAND HYGIENE SURVEY. Yes: If yes, has this policy been signed and approved by the CEO and/or the board of directors? Yes No

Implementation of the new 'Pet Regulation' Regulation (EU) No 576/2013

Safe Work Method Statement. Mouse Blood Collection

4-H Livestock Quality Assurance Program

Antimicrobial Stewardship Team - Pilot Proposal

Lesson Plan. Grade Level

Key Messages & RDE Priorities

Intravenous Gentamicin Use in Adults (HARTFORD Guidance)

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

APPLICATION FOR LIVE ANIMAL USE IN TEACHING AT COASTAL ALABAMA COMMUNITY COLLEGE

Transcription:

Turtle Graphics Recursin with Turtles Pythn has a built-in mdule named turtle. See the Pythn turtle mdule API fr details. Use frm turtle imprt * t use these cmmands: CS111 Cmputer Prgramming Department f Cmputer Science Wellesley Cllege fd(dist) bk(dist) rt(angle) pu() pd() pensize(width) penclr(clr) shape(shp) hme() clear() reset() setup(width,height) turtle mves frward by dist turtle mves backward by dist turtle turns left angle degrees turtle turns right angle degrees (pen up) turtle raises pen in belly (pen dwn) turtle lwer pen in belly sets the thickness f turtle's pen t width sets the clr f turtle's pen t clr sets the turtle's shape t shp turtle returns t (0,0) (center f screen) delete turtle drawings; n change t turtle's state delete turtle drawings; reset turtle's state create a turtle windw f given width and height 10-2 A Simple Example with Turtles frm turtle imprt * setup(,) fd(100) lt(60) shape('turtle') penclr('red') fd(150) rt(15) penclr('blue') bk(100) pu() bk(50) pd() pensize(5) bk(250) pensize(1) hme() 10-3 Lping Turtles Lps can be used in cnjunctin with turtles t make interesting designs. plygn(3,100) # Draws a plygn with the specified number # f sides, each with the specified length def plygn(numsides, sidelength): plygn(4,100) plygn(6,60) plygn(100,3) plygn(5,75) plygn(7,50) 10-4

Lping Turtles Spiraling Turtles: A Recursin Example # Draws "flwers" with numpetals arranged arund # a center pint. Each petal is a plygn with # petalsides sides f length petallen. def plyflw(numpetals, petalsides, petallen): plyflw(7,4,80) plyflw(10,5,75) plyflw(11,6,60) spiral(200,90,0.9,10) spiral(200,72,0.97,10) spiral(200,80,0.95,10) 10-5 spiral(200,121,0.95,15) spiral(200,95,0.93,10) 10-6 spiral(sidelen, angle, sidelen is the length f the current side angle is the amunt the turtle turns left t draw the next side scalefactr is the multiplicative factr by which t scale the next side (it is between 0.0 and 1.0) minlength is the smallest side length that the turtle will draw Spiraling Turtles: A Recursin Example def spiral(sidelen, angle, : spiral(, 90, 10-7 10-8

spiral(, 90, spiral(, 90, spiral(, 90, if sidelen >= minlength: 10-9 10-10 spiral(, 90, spiral(, 90, spiral(, 90, spiral(, 90, fd() 10-11 10-12

spiral(, 90, spiral(, 90, spiral(, 90, fd() spiral(, 90, fd() if sidelen >= minlength: 10-13 10-14 spiral(, 90, spiral(, 90, spiral(, 90, fd() spiral(, 90, fd() fd() 10-15 10-16

spiral(, 90, spiral(, 90, spiral(, 90, fd() spiral(, 90, fd() fd() fd() 10-17 if sidelen >= minlength: 10-18 spiral(, 90, spiral(, 90, spiral(, 90, fd() spiral(, 90, fd() fd() fd() 10-19 10-20

spiral(, 90, spiral(, 90, spiral(, 90, fd() spiral(, 90, fd() fd() fd() 10-21 spiral(, 90, spiral(, 90, if sidelen >= minlength: 10-22 spiral(, 90, spiral(, 90, spiral(, 90, fd() spiral(, 90, fd() fd() fd() spiral(, 90, spiral(, 90, 10-23 spiral(, 90, spiral(, 90, fd() 10-24

spiral(, 90, spiral(, 90, spiral(, 90, fd() spiral(, 90, fd() fd() fd() spiral(, 90, if sidelen >= minlength: spiral(, 90, spiral(, 90, fd() 10-25 spiral(, 90, spiral(, 90, fd() spiral(, 90, 10-26 spiral(, 90, spiral(, 90, spiral(, 90, fd() spiral(, 90, fd() fd() spiral(, 90, fd() spiral(, 90, fd() spiral(, 90, spiral(, 90, fd() spiral(, 90, 10-27 spiral(, 90, spiral(, 90, fd() spiral(, 90, 10-28

spiral(, 90, spiral(, 90, spiral(, 90, fd() spiral(, 90, fd() spiral(204.8, 90, if sidelen >= minlength: fd() spiral(, 90, fd() fd() spiral(, 90, fd() spiral(204.8, 90, spiral(, 90, spiral(, 90, fd() spiral(, 90, 10-29 spiral(, 90, spiral(, 90, fd() spiral(, 90, 10-30 spiral(, 90, spiral(, 90, spiral(, 90, fd() spiral(204.8, 90, if False: spiral(, 90, fd() fd() spiral(, 90, fd() spiral(204.8, 90, fd() spiral(, 90, fd() spiral(204.8, 90, spiral(, 90, spiral(, 90, fd() spiral(, 90, 10-31 spiral(, 90, spiral(, 90, fd() spiral(, 90, 10-32

spiral(, 90, spiral(, 90, spiral(, 90, fd() spiral(, 90, fd() fd() fd() spiral(, 90, spiral(, 90, fd() spiral(, 90, 10-33 spiral(, 90, 10-34 spiral(, 90, spiral(, 90, spiral(, 90, fd() spiral(, 90, fd() fd() 10-35 10-36

spiral(, 90, Invariant Spiraling A functin is invariant relative t an bject s state if the state f the bject is the same befre and after the functin is invked. # Draws a spiral. The state f the turtle (psitin, # clr, heading, etc.) after drawing the spiral is the # same as befre drawing the spiral. def spiralback(sidelen, angle, : 10-37 10-38 Zigzags zigzag(1, 10) Trees zigzag(4, 10) # Draws the specified number f zigzags with the specified # length. def zigzag(num, length): if num>0: lt(45) fd(length) rt(90) fd(2*length) fd(length) zigzag(num-1, length) tree(7, 75, 30, 0.8) tree(7, 75, 15, 0.8) Exercise: mdify zigzag t make the turtle s state invariant. 10-39 tree(10, 80, 45, 0.7) tree(10, 100, 90, 0.68) 10-40

Hw t make a 4 level tree: tree(4, 100, 45, 0.6) Hw t make a 3 level tree: tree(3, 60, 45, 0.6) and tw level 3 trees with 60% trunks set at 45 angles and tw level 2 trees with 60% trunks set at 45 angles Make a trunk f size 60 Make a trunk f size 100 10-41 10-42 Hw t make a 2 level tree: tree(2, 36, 45, 0.6) Hw t make a 1 level tree: tree(1, 21.6, 45, 0.6) and tw level 1 trees With 60% trunks set at 45 angles and tw level 0 trees set at 45 angles Make a trunk f size 36 Make a trunk f size 21.6 10-43 10-44

Hw t make a 1 level tree: tree(0, 12.96, 45, 0.6) tree(levels, trunklen, angle, shrinkfactr) D nthing! levels is the number f branches n any path frm the rt t a leaf trunklen is the length f the base trunk f the tree angle is the angle frm the trunk fr each subtree shrinkfactr is the shrinking factr fr each subtree 10-45 10-46 Trees Tracing the invcatin f tree(3, 60, 45, 0.6) def tree(levels, trunklen, angle, shrinkfactr): 10-47 10-48

Draw trunk and turn t draw level 2 tree Begin recursive invcatin t draw level 2 tree 10-49 10-50 Draw trunk and turn t draw level 1 tree Begin recursive invcatin t draw level 1 tree 10-51 10-52

Draw trunk and turn t draw level 0 tree Begin recursive invcatin t draw level 0 tree 10-53 10-54 Cmplete level 0 tree and turn t draw anther level 0 tree Begin recursive invcatin t draw level 0 tree 10-55 10-56

Cmplete level 0 tree and return t starting psitin f level 1 tree Cmplete level 1 tree and turn t draw anther level 1 tree 10-57 10-58 Begin recursive invcatin t draw level 1 tree Draw trunk and turn t draw level 0 tree 10-59 10-60

Cmplete tw level 0 trees and return t starting psitin f level 1 tree Cmplete level 1 tree and return t starting psitin f level 2 tree 10-61 10-62 Cmplete level 2 tree and turn t draw anther level 2 tree Draw trunk and turn t draw level 1 tree 10-63 10-64

Draw trunk and turn t draw level 0 tree Cmplete tw level 0 trees and return t starting psitin f level 1 tree 10-65 10-66 Cmplete level 1 tree and turn t draw anther level 1 tree Draw trunk and turn t draw level 0 tree 10-67 10-68

Cmplete tw level 0 trees and return t starting psitin f level 1 tree 10-69 Cmplete level 1 tree and return t starting psitin f level 2 tree 10-70 Cmplete level 2 tree and return t starting psitin f level 3 tree bk(60) 10-71 The squirrels aren't fled 10-72

Randm Trees Turtle Ancestry def treerandm(length, minlength, thickness, minthickness, minangle, maxangle, minshrink, maxshrink): if (length < minlength) r (thickness < minthickness): # Base case pass # D nthing else: angle1 = randm.unifrm(minangle, maxangle) angle2 = randm.unifrm(minangle, maxangle) shrink1 = randm.unifrm(minshrink, maxshrink) shrink2 = randm.unifrm(minshrink, maxshrink) pensize(thickness) fd(length) rt(angle1) treerandm(length*shrink1, minlength, thickness*shrink1, minthickness, minangle, maxangle, minshrink, maxshrink) lt(angle1 + angle2) treerandm(length*shrink2, minlength, thickness*shrink2, minthickness, minangle, maxangle, minshrink, maxshrink) rt(angle2) pensize(thickness) bk(length) 10-73 Flr turtles used t teach children prblem slving in late 1960s. Cntrlled by LOGO prgramming language created by Wally Feurzeig (BBN), Daniel Bbrw (BBN), and Seymur Papert (MIT). Lg-based turtles intrduced arund 1971 by Papert s MIT Lg Labratry. Turtles play a key rle in cnstructinist learning philsphy espused by Papert in Mindstrms (1980). 10-74 Turtle Ancestry (cnt d) Turtles, Buggles, & Friends At Wellesley Richard Pattis s Karel the Rbt (1981) teaches prblem-slving using Pascal rbts that manipulate beepers in a grid wrld. Turtle Gemetry bk by Andrea disessa and Hal Abelsn (1986). LEGO/Lg prject at MIT (Mitchel Resnick and Steve Ock, 1988); evlves int Handybards (Fred Martin and Brian Silverman), Crickets (Rbbie Berg @ Wellesley), and LEGO Mindstrms StarLg prgramming with thusands f turtles in Resnick s Turtles, Termites, and Traffic Jams (1997). 10-75 In mid-1980s, Eric Rberts teaches prgramming using sftware-based turtles. In 1996, Rbbie Berg and Lyn Turbak start teaching Rbtic Design Studi with Scibrgs. In 1996, Randy Shull and Takis Metaxas use turtles t teach prblem slving in CS110. In 1997, BuggleWrld intrduced by Lyn Turbak when CS111 switches frm Pascal t Java. Turtles are als used in the curse In 2006, Rbbie Berg and thers intrduce PICO Crickets: http://www.piccricket.cm In 2011, Lyn Turbak and the TinkerBlcks grup intrduce TurtleBlcks, a blcks-based turtle language whse designs can be turned int physical artifacts with laser and vinyl cutters. 10-76

Laser Cutting a Tree regular mde bundary mde laser cutting TurtleWrld 10-77