CMU 15-112 Summer 2020: Fundamentals of Programming and Computer Science
Homework 6 (Due Fri 29-May, at 5pm)
- This assignment is SOLO. This means you may not look at other student's code or let other students look at your code for these problems. See the syllabus for details.
- To start:
- Create a folder named 'hw6'
- Download all three of these files into that folder:
- Edit hw6.py using VSCode
- When you are ready, submit hw6.py to Autolab. For this hw, you may submit up to 10 times, but only your last submission counts.
- Do not use sets, dictionaries, or recursion in this assignment.
- Do not hardcode the test cases in your solutions.
- NOTE: Make sure all graphics code (including the tkinter import) goes below the ignore_rest line.
- NOTE: This homework is going to be graded for style. Make sure that you adhere to the style guide when you're working on this HW, and double check your file against the style guide before you submit to Autolab!
A note about hw6 spicy scoring.
The maximum score on hw6 is 55 points. drawSudokuBoard and drawChessBoard are each 50 point problems which (along with reviewing your test1 feedback) will give you a full score. You may complete drawSpiral for an extra 20 spicy points which will be reflected in the spicyScore category of autolab (but which will not give you a 70/50 on this assignment). drawSpiral is outside of the week 2 spicy track, so you may complete both drawSudokuBoard and drawSpiral.
- Review Your Test1 Feedback [5 pts - Required]
Open up Gradescope and review your feedback from test1. Think about how you'd fix your errors, write up any problems you didn't get to, and talk to a TA if you have questions about your feedback or the test problems themselves. Use this test as the learning tool it is!
- drawSudokuBoard(canvas, width, height, board, margin) [50 pts - Medium] [manually graded]
Write the function drawSudokuBoard that draws a sudoku board as follows:
Here are some details on the parameters:- board is a NxN list of integers. You may assume that it contains only integers.
- margin is the distance between the grid and the edge of the screen.
You must satisfy the following additional requirements to get full credit:- Your code should be able to handle any NxN board size with at least 4 rows. That is, we can give you a board that is 4x4, 9x9, etc. The size of the board should adjust to fit the whole board on the screen.
- You should be able to handle any canvas size (where the width and heigth may not be equal). The size of the board should adjust to fit the whole board on the screen.
- Make sure to have all of the details in the picture: the thicker lines, the numbers, etc.
- Your margin must be exactly what we specified. That is: your board must expand to fill up the full screen leaving only the margin given as whitespace.
- Choose a reasonable font size that works with most boards. You don't have to adjust that font size when the canvasSize/margin/board dimensions change.
Here's an example of a board with a large margin:
Here's an example of a board that is 4x4:
Here's an example of a board that has a small canvasSize:
- drawChessBoard(canvas, width, height, board, color, margin) [50 pts - Spicy] [manually graded]
Write the function drawChessBoard that draws a chess board as follows:
Here are some details on the parameters:- board is a NxM list of strings. You may assume that it contains only spaces and unicode chess characters.
- color is the an rgb tuple representing the color of the margin. "Lightening" color gives you the color of the non-white squares on the board.
- margin is the distance between the grid and the edge of the screen.
You must satisfy the following additional requirements to get full credit:- Your code should be able to handle any board size that is rectangular and has at least 4 rows. It should be able to draw a standard chess board, a Simplified Chess board, a solitaire chess board, etc. We can give you a board that is 4x4, 7x8, etc. The size of the board should adjust to fit the whole board on the screen.
- You should be able to handle any width and height. The size of the board should adjust to fit the whole board on the screen.
- Your margin must be exactly what we specified. That is: your board must expand to fill up the full screen leaving only the margin given as colored space.
- Your font size must adjust with the size of the board. Pick a reasonable ratio between your square/cell size and your font size.
- Your board should have a checkerboard pattern, with the top left square always being white
- Your non-white squares should be a "lightened" version of your color parameter. You can lighten an rgb color by adding a constant amount to the r, g, and b values (but make sure they're capped at 255!). See the rgbString function from the graphics notes to turn this tuple into a tkinter-compatible color. You may choose any reasonable constant to lighten by.
Here's an example of a green Simplified Chess board with a large margin:
Here's an example of an orange solitaire chess board with no margin (note that since lightened orange looks yellow, the non-white squares here are yellow):
- drawSpiral(canvas, width, height) [20 pts - Spicy] [manually graded]
Write a function named drawSpiral(canvas, width, height) that takes two ints and creates a window of the given dimensions, and then draws this picture (to fill the window as completely as possible):
Here, you will draw both sides of the picture (the larger and smaller spirals), along with the title text (drawSpiral) and the boxes around the spirals.
As for the image, each side will be a spiral (or really a series of spiral arms). The spiral arms must be created by drawing a series of circles (the only thing drawn to create the spirals in this exercise are small circles). There should be 28 arms, each arm composed of 32 circles. Each arm spirals, or bends, such that the outermost circle in the arm is drawn pi/4 radians (45 degrees) beyond the innermost circle in that same arm. Hint: You will have to use basic trigonometry here! Also, try to make the color gradients work as indicated (think rgbString).