@extends('template') @section('title') Lab 4: Quilt Pictures @stop @section('content') # Lab 4: Quilt Pictures ## Reference + [Lecture 5: Divide, Conquer, and Glue with Pictures](/content/lectures/lec05_DCG/files/lec05_DCG.pdf) ## Visual crash course in `picture.py` functions ## OPTIONAL: Pencil and Paper practice Discuss with your partner if you want to start on paper, or jump directly to code in Task 1 below. Given the following code, draw the resulting pictures below: ```py from picture import * def makeAPic1(c1): block = patch(c1) check = fourPics(block, empty(), empty(), block) return check def makeAPic2(c1): pic1 = makeAPic1(c1) return fourSame(pic1) def makeAPic3(c1,c2): pic2 = makeAPic2(c1) underneath = patch(c2) return overlay(pic2, underneath) # What picture is displayed? displayPic(makeAPic1('blue')) # What picture is displayed? displayPic(makeAPic2('blue')) # What picture is displayed? displayPic(makeAPic3('red','yellow')) ``` {{-- Note to Sohie, pics are in pic, pic2, and pic3.png --}} ## Setup In your `lab04` folder, create a new file called `quilts.py`. After adding the usual identifying comments at the top of this file (name, date, assignment, etc.), include the following line to import the picture functions you'll need in this task. ```py from picture import * ``` Note: `picture.py` is included in the `lab04` folder. If Canopy does not find this file when you run your code, check that your **working directory** is synced to your `lab04` folder. ## Task 1 Your first goal is to write a function called `plusSign` that __takes two color parameters__ and __returns a picture__ that looks like these examples: `plusSign('green','gray')` |    | `plusSign('darkred','paleturquoise4')` -----| :-----: | :----- |    | First, make a mental note of what functions provided in `picture.py` might help you accomplish this task. + ? + ? + ? + Others? Next, focus on just one quadrant, the upper right: Note how this quadrant is a composite of 2 pictures, a mini green patch, and a gray patch. One approach to this task is to define separate functions that can help us create these individual pieces, and then glue them together. For example... ### Function 1 `upperRightNest(p1)` A helper function to nest a picture (p1) in the upper right corner at 1/4 the original size. Can be used to create the mini green patch: Test: ```py displayPic(upperRightNest(patch('green'))) ``` Should use: Any function(s) from picture.py you might need. ### Function 2 `block(c1, c2)` A helper function to create the upper right quadrant of the final picture, i.e. the mini green patch on top of a gray patch: Test: ```py displayPic(block('green','gray')) ``` Should use: `upperRightNest`, and whatever function(s) from picture.py you might need. ### Function 3 `plusSign(c1, c2)` The “glue” function that utilizes the above 2 helper functions to create your final picture. Test: ```py displayPic(plusSign('green','gray')) ``` Should use: `upperRightNest`, `block`, and whatever function(s) from picture.py you might need. ## Task 2 Following similar strategies employed in Task 1, write a function called `diamond` that takes two colors and returns the picture shown below. Your function must work for any two color parameters. You can use any of the helper functions you defined in Task 1, as well as any of the functions in picture.py. `diamond('green','gray')` |    | `diamond('darkred','paleturquoise4')` :----- | ----- | : ------ |    | ## Task 3 Write a function called `stripesAndSquares` that **takes two colors** and **returns the picture** shown below. Your function must work for any two color parameters. `stripesAndSquares('green','gray')` |    | `stripesAndSquares('darkred','paleturquoise4')` :----- | ----- | : ------ |    | ## Task 4: A quilt with 'folds' Write a function called `fold()` that takes two colors and returns the picture shown below. Your function must work for any two color parameters. `fold('green','gray')` |    | `fold('darkred','paleturquoise4')` :----- | ----- | : ------ |    | ## Task 5: And an even fancier quilt Write a function called `fancyFold()` that **takes two colors** and **returns the picture** shown below. Study the upper right quadrant carefully before you begin to code. Try to work out on paper how the quadrant (shown below) is constructed. `fancyFold('green','gray')` |    | `fancyFold('darkred','paleturquoise4')` :----- | ----- | : ------ |    | ## Task 6: The hanky quilt (time permitting) Write a function `hanky` that **takes three colors** and **returns the picture** shown below. Again, start by studying the quilt first, then think about your code. `hanky('green','gray','lightblue')` |    | `hanky('darkred','paleturquoise4','pink')` :----- | ----- | : ------ |    | @include('/labs/lab04/_toc') @stop