Exercise (1) What does function chai draw? def chai(size):

Slides:



Advertisements
Similar presentations
First of all – lets look at the windows you are going to use. At the top you have a toolbar, with all your various tools you can use when customising your.
Advertisements

40S Applied Math Mr. Knight – Killarney School Slide 1 Unit: Sequences Lesson: SEQ-L3 Drawing Fractal Patterns Drawing Fractal Patterns Learning Outcome.
COMPSCI 105 S Principles of Computer Science
Geometry Day 41 Polygons.
Geometry 5 Level 1. Interior angles in a triangle.
Unit 7 Polygons.
Regular Polygons. Introduction A Polygon is a many-sided shape. A Regular Polygon is a many-sided shape with all sides and angles the same. An important.
Super Logo. Key Instructions Pendown penup Forward 50 ( this number can change) Right 90 ( this number can change as well) Now try and draw a Early finishers,
Polygons Test Review. Test Review Find the missing angle. 50.
Symmetry Reflectional Rotational G. CO. 3 Given a rectangle, parallelogram, trapezoid, or regular polygon, describe the rotations and reflections that.
The Wonderful World of Fractals
EECS 110: Lec 6: Fractals and Trutles Aleksandar Kuzmanovic Northwestern University
7.3 Formulas involving polygons
Sum of Interior angles.
Classifying Polygons Objective; I can describe a polygon.
Geometric Symmetry and Tessellations Chapter 10 sec. 6.
RECURSION Recursion Towers of Hanoi To Recurse or to Loop? Fractals Do something!
Log on and Download from website:
Unit 4: Shapes and Space Ms Cormier April 23 rd, 2010.
Fall Week 3 CSCI-141 Scott C. Johnson.  Say we want to draw the following figure ◦ How would we go about doing this?
Polygon Angles. Naming by # of sides. Polygons have specific names based on the number of sides they have: 3 – Triangle 4 – Quadrilateral 5 – Pentagon.
Transparency 7 Click the mouse button or press the Space Bar to display the answers.
Class 2 Introduction to turtle graphics
A new human-computer interface?
POLYGONS POLYGONS Moody Mathematics. What is the term for a 3- sided polygon? Triangle Moody Mathematics.
1 Geometry Section 6-3A Regular Polygons Page 442.
CP Geometry Mr. Gallo. Shapes for the next page. Draw all the diagonals possible from only one vertex. Use the information in the chart on the next page.
More with interior and exterior angles of polygons
CS 121 Today Fractals and Turtles! The Koch Curve how random…
Coming Attractions: regular It is regular because it fits together with no gaps. hexagon.
EECS 110 Recitation #3 Ning Xia Northwestern University.
Basic Geometry Review-Shapes and Angles. Review Topics Squares Triangles Rectangles Polygons Obtuse Angle Acute Angle Right Angle Finished?
Bell Work Find x Find x and y.
5.1 Polygon Sum Conjecture
What is a “polygon”? = a closed shape with straight line segments.
Programming Training kiddo Main Points: - Python Statements - Problems with selections.
Day 2. Prism and Pyramid In what ways are these shapes alike? In what ways are these shapes different? Distribute set.
First of all – lets look at the window’s you are going to use. At the top you have a toolbar, with all your various tools you can use when customising.
POLYGONS. Learning Goals LG: Describe and compare the sides and angles of regular and irregular polygons. Kid Friendly: Be able to tell the difference.
Functions. functions: a collection of lines of code with a name that one can call. Functions can have inputs and outputs.
Polygons and Triangles Review and Introduction. Activator - Match the definitions to their vocabulary term. Then draw 2 of the figures. 1. A triangle.
Geometry 3-4 Polygon Angle Sum Theorems. Vocabulary.
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.
Using Logo to explore spiral patterns. Paul Broadbent Spiral patterns This is a (1,2,3) spiral path. It repeats lines of three.
Introduction to Python
Polygons and angles.
7-5 Polygons Course 2 Warm Up Problem of the Day Lesson Presentation.
What common points can we observe on these images? Do we often find this in architecture?
Iterative Mathematics
CS 1321.
Tuesday, January 22, 2013 Agenda: TISK & 2 MM Review HW answers
Polygons – Measurements of Angles
UNIT 3 – LESSON 5 Creating Functions.
7.4 Regular polygons Objective:
Radial differentiation slide
We are removing the 4th part of hw2pr2 for now.
Evgeniya Gushchina EPAM e-kids volunteer computer science teacher
Learning to program with Logo
Frozen Graphics Lesson 3.
The CS 5 Times “Zach and Geoff to be Replaced by
Learning to Program in Python
The Wonderful World of Fractals
Chap. 3 Functions Start Python IDLE (Shell) and open a new file.
Section 3 Programming with Turtle Graphics
Recursion Taken from notes by Dr. Neil Moore
8-5 Classifying Polygons Warm Up Problem of the Day
Welcome GCSE Maths.
Background for lab: the ord() function
CMPT 120 Lecture 19 – Unit 3 – Graphics and Animation
2 Making Blocks.
Presentation transcript:

Exercise (1) What does function chai draw? def chai(size): """ mystery! """ forward(size) left(90) forward(size/2.0) right(90) backward(size) Why are there two identical commands in a row? How could you add more to each end?

Then you will be able to write functions using turtle commands: Turtle Graphics We will be using Python’s built-in turtle graphics package. You will want to have this line in your hw2pr3.py file: from turtle import * Then you will be able to write functions using turtle commands: http://docs.python.org/release/3.1.3/library/turtle.html Turtle reference Also see link in the homework For basic help on Python's turtle graphics module

Recursive Graphics (1) Could we tri this with recursion? do... or do not... there is no tri … (1) Could we tri this with recursion? def tri(): """ draws a polygon """ forward(100) left(120) def tri( ): """ draws a polygon """ def triRec(n=3): if n == 0: return else: forward(100) left(120) triRec(n-1) EVERYTHING IN CS IS PATTERNS. WHAT IS THE PATTERN THAT I CAN TEASE OUT HERE? GOING BACK TO YOUR LEGO DAYS… Illustrate by example. Draw square, and pentagon. (2) Could we create any regular n-gon?

Generic n-gon A default parameter value! def ngon(nSides,curSide=0): """ A simple recursive function to create an arbitrary n-sided polygon Parameters: n - Number of sides of the polygon curSide - used by the recursion """ if curSide >= nSides: return else: forward(100) left(360/nSides) ngon(nSides,curSide+1) How many degrees should we turn?

ngon(nSides) pencolor('red') ngon(3) pencolor('orange') ngon(4) pencolor('yellow') ngon(5) pencolor('green') ngon(6) pencolor('blue') ngon(7)

Drawing Recursively Any self-similarity here? 190 200

Designing any recursive program boils down to the same two pieces Drawing Recursively Designing any recursive program boils down to the same two pieces Think about the SIMPLEST POSSIBLE case! Base Case: Do ONLY ONE STEP, and let recursion do the rest… Recursive Step:

Designing any recursive program boils down to the same two pieces Drawing Recursively Designing any recursive program boils down to the same two pieces def spiralSquare(x): if x < 1: return else: forward(x) left(90) spiralSquare(x-10) Base Case call spiralSquare(x), where x == number of moves Recursive Step What if we had forgotten the base case?

Drawing Recursively Try writing these functions: def spiralTri(x): Draws a triangular (equilateral) spiral. Try it! spiralTri(200) draws def spiralOct(x): Draws an octagonal spiral. Try it! spiralOct(100) draws def spiralLim(x, n): Draws a square spiral with only n segments! actually, a bit larger than this … Try it! spiralLim(200, 7) draws

close-up of innermost part of the spiral… hw2pr3 spiral 81 72.9 90 close-up of innermost part of the spiral… spiral( 100, 90, 0.9 ) 100 spiral(initLength, angle, multiplier)

svTree( trunkLength, levels ) hw2pr3 svTree Level 1 Level 2 Level 3 For the next program we are going to draw a fractal tree. Fractals come from a branch of mathematics, and have much in common with recursion. The definition of a fractal is that when you look at it the fractal has the same basic shape no matter how much you magnify it. Some examples from nature are the coastlines of continents, snowflakes, mountains, and even trees or shrubs. The fractal nature of many of these natural phenomenon makes it possible for programmers to generate very realistic looking scenery for computer generated movies. In our next example we will generate a fractal tree. To understand how this is going to work it is helpful to think of how we might describe a tree using a fractal vocabulary. Remember that we said above that a fractal is something that looks the same at all different levels of magnification. If we translate this to trees and shrubs we might say that even a small twig has the same shape and characteristics as a whole tree. Using this idea we could say that a tree is a trunk, with a smaller tree going off to the right and another smaller tree going off to the left. If you think of this definition recursively it means that we will apply the recursive definition of a tree to both of the smaller left and right trees. Level 4 svTree( 100, 4 ) I wonder what happened to the leaves on that tree… ? svTree( trunkLength, levels )