Problem Set 2 - Due Tue, Feb 12 at 23:59
- Goldwasser & Letscher, Chapter 3, sections 3.3-3.6, pages 103-110.
- Slides and notebooks from Lec 3.
- Problems and solutions from Lab 2.
About this Problem Set
Task 1 is an individual problem in which you will get practice with debugging in the context of fixing a misbehaving graphics program.
- Task 2 is a task that explores abstraction in the
cs1graphicstransformations and layers. In this problem, having a partner is optional but strongly recommended. If you want to have a partner, use this shared Google Doc to find a pair programming partner and record who your pair partner is. Please do not use students-cs111-s19 to find partners.
Reminder: Collaboration and honor code: you can talk with other individuals and teams about high-level problem-solving strategies, but you cannot share any code with them.
There is a completely optional Task 3 that you can do for fun, if you wish. No extra credit points will be awarded for Task 3.
The CS111 Problem Set Guide gives an overview of psets, including a detailed description of individual and partner tasks.
Follow the practices discussed in our CS111 Code Style Guide.
In Spring 2018, students spent the following times (in hours) on the two required tasks:
Task Average Median 25% took more than 10% took more than Task 1 2.3 2.0 2.5 4.4 Task 2 3.0 2.2 4.0 5.0
- All code for this assignment is available in the
ps02folder in the
cs111/downloaddirectory within your
Task 1: Debugging Graphics
This is an individual problem which you must complete on your own, though you may ask for help from the CS111 staff.
Using layers and transformations in
cs1graphics, we want to create the
following picture, which contains 4 transformed versions of a face:
Relative to the upper left face:
- The lower left face is twice as big.
- The upper right face is 80% as big.
- The lower right face is 1.5 times as big.
We have supplied you with a program that attempts to create the above picture.
Click here to see the program,
a copy of which can be found in the
ps02 folder as
Although it is structured well and in many ways is close to correct,
the program generates the following incorrect picture due to
Your goal in this subtask is to fix this program so that it generates the correct picture. In the
ps02 folder is a file
debugGraphicsFixed.py that is
initially a copy of the buggy
debugGraphicsBuggy.py program with some
extra header information at the top that you should fill out and an extra
triple-quoted comment section at the bottom (more on this below). You should
debugGraphicsFixed.py by finding and fixing all the bugs it contains,
so that it ultimately generates the correct picture.
Do not make any changes to
debugGraphicsBuggy.py. You should change only
cs1GraphicsHelpermodules. These are very useful for finding and fixing the bugs in the program. Review the Lecture 03 notebook for how to use these two modules for debugging programs that use
Most changes require modifying/replacing existing lines in the program. It is never necessary to completely remove any lines from the program. It is necessary to add only two missing lines to the program.
As in the PS01 Task 1 Debugging Numbers problem, you should use an incremental strategy for debugging. In this case, at every step, you should focus on just one thing that is wrong with the picture. Search for the place in the program that causes this bug, attempt to fix it, and test your modified program to see if it makes the resulting picture closer to correct. If your bug fix doesn't improve the picture, try again. If it does fix a broken aspect of the picture, focus on a new bug in the program. Keep doing this until the generated picture is correct.
As in the PS01 Task 1 Debugging Numbers problem, we want you to define variables
fix2, etc. that give a brief summary of each bug in Bud's program and how you fixed it:
- For each bug number _n_, you should assign a new variable named `bug`_n_
to a triple-quoted string that describes the bug.
+ In cases where a line of the program is wrong, give the line number from <a href="/content/psets/ps02/debugGraphicsBuggy.html" target="_blank">The original `debugGraphicsBuggy.py` program</a> and explain why that line is wrong. + In the two cases where you need to add lines of missing code, explain why you need to add a new line of code. - For each bug number _n_, you should assign a new variable named `fix`_n_ to a triple-quoted string that describes how you fixed the bug in your
+ In cases where a line of the program is wrong, explain how you fixed the bug. + In the two cases where you need to add a line of missing code, explain what that code does and the line where you added it in the program (using line numbers from the original program).<br><br>
- Use Codder to get feedback on
debugGraphicsFixed.pyprogram. Codder will compare the image generated by your program to the expected image and the differences will be highlighted in red. Click here for an example of Codder feedback illustrating this, where the difference in the images is highlighted in red in the top right face under "Similarity Status".
Task 2: Bunny Money Pattern
This task is required and you have the option to work with a partner on it if you wish. We strongly encourage you to work in pairs on this problem. Use this shared Google Doc to find a pair programming partner and record pair programming partnership.
Your goal in this task is to generate the following picture by fleshing out the file
bunnyMoneyMosaic.py in the
There is a lot of stuff going on in this picture. You can see that one pattern is repeated, at different sizes and rotations. Let's call this pattern
bunnyMoney, as shown below (enlarged):
bunnyMoneyMosaic.py file begins by importing the following shapes to get
you started; the rest you will create using
Two graphics objects that are provided for you:
This is a layer that is returned by calling the
Its reference point is marked by an orange circle.
This is an
Its reference point is in its upper left corner.
In general, we recommend that you start with pencil and paper (as opposed to jumping into Canopy). You want to build your code incrementally, making sure that smaller parts work before attempting the entire picture.
- The large green (
lightgreen) rectangle has a width of 600 and height of 300
- The blue (
navy) circle in the center of the
bunnyMoneyhas a radius of 75
- Each of the small wedges + bunny on the navy circle are one-quarter the size of the original wedge + bunny
- The grey (
darkgrey) rectangle has a width of 330 and height of 70
- The top-left bunny's head is located at (75, 120).
- This set of slides give a high-level overview of how to make bunny money.
- Here is
bunnyMoneyshown with a gridlines spaced 50 apart and also with gridlines spaced 25 apart (use the grids to figure out where to place things):
Bunny Money Mosaic information that will be useful for you:
- The pink canvas has dimensions 900x600
- The 900x600 bunny money mosaic with grid is shown here:
- Note that the ears of the bunny are always outlined in white; sometimes the bunny is scaled smaller and the ears may appear to be non-white, but rest assured they retain their original color.
In your program, you should define the following variables that contain layers with pictures described in the bunny money slides:
bunnyMoneyMosaic.pyshould create a canvas with the desired mosaic pattern.
- Use Codder to get feedback on
Task 3: Fancy Bunny Money [THIS IS AN OPTIONAL TASK]
If you had fun making bunny money and have time to spare, then you can complete
this OPTIONAL task. In this OPTIONAL task, the goal is to create this
picture in the file
The image is very similar to the one in Task 2 above, but has a line of bunnies in the grey rectangle.
Useful fancy bunny money tips:
- Here is an enlarged view of fancy bunny money with a grid (each grid line is 50 units apart):
- The smaller bunnies are 30% the size of the original bunny; the larger bunnies are 42% the original size.
- Here is an enlarged closeup of the line of bunnies with a grid (each grid line is 10 units apart):
This gives information about where to place each bunny.
Task 4: Honor Code Form
ps02 folder contains a file
honorcode.py with several variable
assignments for your name, the time you spent on the tasks, etc. Change the
values in these variable assignments to appropriate values.
How to turn in this Problem Set
Softcopy (electronic) submission:
It's a good idea to run Codder one last time on each
.pyfile you worked on before you submit it.
For Task 1, save your final
debugGraphicsFixed.pyfile in the
ps02folder. Make sure you have filled out the comment header at the top with your name, username, and submission date.
For Task 2, each team member should save their
bunnyMoneyMosaic.pyfile in their
ps02folder. If you worked with a partner on this problem. this file should contain a comment with names of both partner and usernames at the top, in addition to the submission date.
If you did the optional Task 3, save your
fancyBunnyMoneyMosaic.pyfile in your
ps02folder. This file should contain a comment with your name, username, and submission date at the top
Save your filled out
Note: It is critical that the name of the folder you submit is
ps02, and your submitted files are named exactly as specified above. In other words, do not rename the folder that you downloaded, do not create new files or folders, and do not delete or re-name any of the existing files in this folder. We have automated scripts to check your electronic submission: an improperly named folder will not count as a valid submission.
Drop your entire
ps02folder in your
dropfolder on the
csserver using Cyberduck by 11:59pm on the due date = Tuesday February 12, 2019.
- Failure to submit a code file before the deadline will result in zero credit for that code on PS02.
Hardcopy (paper) submission
There is no hardcopy submission. Problem set submission is entirely electronic.