CMU 15-112 Summer 2018: Fundamentals of Programming and Computer Science
Homework 6 (Due Fri 1-Jun, at 5pm)




  1. drawSudokuBoard(canvas, board, margin, canvasSize) [100pts] [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.
    • canvasSize == width of the canvas == height of the canvas.

    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. 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 canvasSize. 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:



  2. Bonus/Optional: drawSpiral(winWidth, winHeight) [3pts]
    Write a function named drawSpiral(winWidth, winHeight) 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).