@extends('template') @section('title') Lab 11, Part 3: Fruitful recursion w/ picture.py patterns @stop @section('content') # Lab 11, Part 3: Fruitful recursion w/ picture.py patterns In `lab11/part3.py` there are two picture variables already defined for you, `block` and `tri`: ``` # Two provided shapes block = clockwise270(overlay(wedge('darkred'), flipAcrossHoriz(wedge('darkred')))) tri = triangles('gray', 'magenta') ``` This is a `block`: This is a `tri`: You'll use these pictures for the tasks in this part of the lab. ## Task 1. Towers Write a **recursive** function called `tower` that creates a vertical stack of pictures as shown below. `tower` takes two parameters: 1. a picture 2. the number of pictures in the tower ### Examples
tower(block, 1) tower(block, 2)
tower(block, 3) tower(block, 4)
tower(tri, 1) tower(tri, 4)
### Hints There are hints in [Helpful Hints and Diagrams](/labs/lab11/hints) (see Table of Contents below), in particular, this [Tower diagram](/content/labs/lab11/hints/pictures-tower.png) may be useful. Look for a smaller version of the same problem in one level, and try to generalize from there. For example, start by figuring out how you'd draw one level: Also, don't forget about the provided functions in `picture.py` which may be used to accomplish your task: - `empty( )` - `clockwise90(p)` - `overlay(p1, p2)` - `flipAcrossHoriz(p1)` - `fourPics(p1, p2, p3, p4)` which produces:
-----------
| p1 | p2 |
|    |    |
-----------
| p3 | p4 |
|    |    |
-----------
## Task 2. Recursive hillsides Write a function called `hillside` that will create pictures like those shown below. Hint: there is only one line of code that differs between the `tower` and `hillside` function.
hillside(block, 1) hillside(block, 2):
hillside(block, 3): hillside(block, 4):
hillside(tri, 1): hillside(tri, 4):
## Task 3. Recursive Mountain (time permitting) *This task is optional; return to it if you complete Part 4 of today's lab and still have time.* Write a recursive function called `mountain` that takes a picture parameter and a number, and returns a picture as shown below. This is a mountain scene with some wintry weather. Remember that you have all the `picture.py` methods available to you. There are hints in [Helpful Hints and Diagrams](/labs/lab11/hints) (see Table of Contents below), in particular, this [Mountain diagram](/content/labs/lab11/hints/pictures-mountain.png) may be useful.
mountain(block, 1): mountain(block, 2):
mountain(block, 3): mountain(block, 4):
mountain(tri, 2): mountain(tri, 4):
--- @include('/labs/lab11/_toc') @stop