Log on and Download from website:

Slides:



Advertisements
Similar presentations
Recursive Strategies Eric Roberts CS 106B January 23, 2013.
Advertisements

New Mexico Computer Science For All
COMPSCI 105 S Principles of Computer Science
Chapter 16 Recursion: Another Control Mechanism. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. a.
Recursion in Python. Recursion Problems in every area of life can be defined recursively, that is, they can be described in terms of themselves. An English.
Cosc 1P02 Week 2 Lecture slides
Graphical position analysis of a 4 bar RRRR linkage Choose your coordinate system and origin.
"Turtle Graphics“ for kids.
Recursion Introduction to Computing Science and Programming I.
Recursion: Overview What is Recursion? Reasons to think recursively? An Example How does recursion work?
CS39N The Beauty and Joy of Computing Lecture #11 Recursion III It has been a challenge to power electronic components implanted within a body.
Programming in Python Turtle Graphics Dr. Kristine Nagel Genie Yang Raquel Lawrence Dr. Kristine Nagel Genie Yang Raquel Lawrence Georgia Gwinnett College.
analysis, plug ‘n’ chug, & induction
B.A. (Mahayana Studies) Introduction to Computer Science November March Logo (Part 1) An introduction to Logo: drawing, moving,
RECURSION Recursion Towers of Hanoi To Recurse or to Loop? Fractals Do something!
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
Mini Project II – Drawing Machine
Chapter 13 Recursion. Topics Simple Recursion Recursion with a Return Value Recursion with Two Base Cases Binary Search Revisited Animation Using Recursion.
12-CRS-0106 REVISED 8 FEB 2013 KUG1C3 Dasar Algoritma dan Pemrograman.
Recursion.
Fall Week 3 CSCI-141 Scott C. Johnson.  Say we want to draw the following figure ◦ How would we go about doing this?
L-Systems and Procedural Plants CSE 3541 Matt Boggus.
Python Programming in Context Chapter 9. Objectives To introduce functional programming style To practice writing recursive functions To introduce grammars.
Chapter 14 Recursion. Chapter Objectives Learn about recursive definitions Explore the base case and the general case of a recursive definition Learn.
Computer Science 111 Fundamentals of Programming I Introduction to Graphics.
By the end of this session you should be able to...
Main Points: - Python Turtle - Fractals
Agent P, I have been hearing some rumours about a Python Turtle.
MSW Logo By Awin 9s.
The Wait-Until-Event pattern Has it happened  Yes, it happened!
CSE 501N Fall ‘09 12: Recursion and Recursive Algorithms 8 October 2009 Nick Leidenfrost.
IB Computer Science Unit 5 – Advanced Topics Recursion.
1/37 Andries van Dam  /27/15 Lecture 14 Recursion.
Getting started with the turtle Find the latest version of this document at
Programming Training kiddo Main Points: - Python Statements - Problems with selections.
Fractal Art. What is Fractal Art? A fractal is a geometric shape that has self similarity, that is it can be split into pieces that are approximate reduced.
Visual C++ Programming: Concepts and Projects Chapter 10A: Recursion (Concepts)
1 Recursion Recursive function: a function that calls itself (directly or indirectly). Recursion is often a good alternative to iteration (loops). Its.
Functions. functions: a collection of lines of code with a name that one can call. Functions can have inputs and outputs.
Progression in KS3/4 Algorithms MONDAY 30 TH NOVEMBER SUE SENTANCE.
Python – Part 4 Conditionals and Recursion. Conditional execution If statement if x>0:# CONDITION print (‘x is positive’) Same structure as function definition.
12-CRS-0106 REVISED 8 FEB 2013 KUG1C3 Dasar Algoritma dan Pemrograman.
LOGO WHAT IS IT? HOW TO USE IT AND HOW USEFUL CAN IT BE?
Drawing!. Why Drawing? Drawing is crucial to any graphical application Understanding.
Functions. functions – learning targets I will be able to understand how to trace function I will be able to learn how to lavage inputs and outputs with.
[ 8.00 ] [ Today’s Date ] [ Instructor Name ]
COMP 51 Week Fourteen Recursion.
Python Turtle Graphics
Fundamentals of Programming I Introduction to Graphics
Data Structures.
Chapter 15 Recursion.
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING
Main Points: - Python Turtle - Fractals
Intro CS – Loops & Creating Shapes
Introduction to Computing Science and Programming I
Chapter 15 Recursion.
Fundamentals of Programming I Introduction to Graphics
Agent P, I have been hearing some rumours about a Python Turtle.
Frozen Graphics Lesson 3.
JavaScript: Functions Part II
Discrete Maths 11. Recursion Objective
Exercise (1) What does function chai draw? def chai(size):
Main Points: - Python Turtle - Fractals
Chapter 11 Recursion.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Chapter 5 Recursion.
CMPT 120 Lecture 18 – Unit 3 – Graphics and Animation
From Barb Ericson Georgia Institute of Technology June 2008
Presentation transcript:

Log on and Download from website: turSnow.py, turSnowDepth.py, RecursiveProgrammingwithTurtles.pptx

Recursive Programming with Python Turtles March 30, 2011 ASFA – Programming II

Children programmed robot turtles to draw pictures Remember: 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) Children programmed robot turtles to draw pictures

How Turtles Draw Think of a turtle crawling on a piece of paper, with a pen tied to its tail Position specified with (x, y) coordinates Cartesian coordinate system, with origin (0, 0) at the center of a window

Turtles Need to Survive as a Species They get tired of just executing simple programs They want to “reproduce” themselves How can they do that? RECURSION

Recursion Two forms of recursion: As a substitute for looping Menu program asking for user input, until eXit selected Breaking a problem down into a smaller problem repeatedly until reach some base case Fibonacci numbers Factorials “Martin and the Dragon” Definition of a recursive method: a method that calls itself

Recursive Algorithm Koch Curve Stages of construction

Drawing a Koch Snowflake specifying length and depth from turtle import * def f(length, depth): if depth == 0: forward(length) else: f(length/3, depth-1) right(60) left(120) f(300, 3)

Alternative Algorithm To draw and Koch curve with length 'x‘ : 1. Draw Koch curve with length x/3 2. Turn left 60degrees. 3. Draw Koch curve with length x/3 4. Turn right 120 degrees. 5. Draw Koch curve with length x/3. 6. Turn left 60 degrees. 7. Draw Koch curve with length x/3. The base case is when x is less than 2. In that case, you can just draw a straight line with length x.

Alternative in Python import turtle def f(length): turtle.shape("turtle") turtle.speed(10) turtle.color(0,.6,.7) if length <= 2: turtle.forward(length) else: f(length/3) turtle.right(60) turtle.left(120) f(200)

Recursive Zoom

Comparing Algorithms Depth/Length Algorithm Length Algorithm from turtle import * def f(length, depth): if depth == 0: forward(length) else: f(length/3, depth-1) right(60) left(120) f(300, 3) What happens if: Length is changed in D/L algorithm? Depth is changed in D/L algorithm? import turtle def f(length): turtle.shape("turtle") turtle.speed(10) turtle.color(0,.6,.7) if length <= 2: turtle.forward(length) else: f(length/3) turtle.right(60) turtle.left(120) f(200) How would you achieve same results in Length algorithm: Length? Depth?

How Draw the Entire Snowflake? We are only drawing one of the 3 sides from the original triangle. How would you draw the entire snowflake?

That’s right just turn and loop 3 times from turtle import * def f(length, depth): if depth == 0: forward(length) else: f(length/3, depth-1) right(60) left(120) f(300, 3) def kflake(size=100,depth=2): for i in range(3): f(size,depth) turtle.left(120) return kflake(100,2)

Some Other Similar Drawings

Assignment Create a recursive turtle drawing of your choosing You must design it on paper first Draw it Pseudocode it Code it Turn them all in via paper (draw and pseudocode) and email (code) Take your time, do something beautiful Sufficient effort must be evident