CMU 15-112 Summer 2018: Fundamentals of Programming and Computer Science
Homework 7 (Due Fri 13-Jul, at 5pm)




  1. Feedback Form [5 pts]
    Fill out this form to let us know how we are doing. This form is anonymous. Please take time to give us meaningful feedback. We want to make this class the best it can be for you! At the end, we will ask you to fill out another form so you get credit on hw3. We won't be able to match up the submissions.

  2. drawStar(canvas, centerX, centerY, diameter, numPoints, color) [25 pts] [manually graded]
    Write the function drawStar which takes a canvas and the star's center coordinates, diameter, number of points, and color, and produces a star based on that specification. To draw a star, we need to identify where to place each of the inner and outer points, then draw them all together as a polygon.

    The outer points of the star should be evenly placed on a circle based on the specified diameter, with the first point at a 90 degree angle. The inner points should then be placed on a circle 3/8 the size of the first circle, halfway between the pairs of outer points. (We use this ratio to make a nice-looking five-pointed star. Actually, the best inner circle would be about 38.2% the size of the outer circle; a little trigonometry and problem-solving will tell you why! But 3/8 is close enough.) An example of how these circles work is shown below.




    For example, this call:
       drawStar(canvas, 250, 250, 500, 5, "gold")
    produces this result:

    And this call:
       drawStar(canvas, 300, 400, 100, 4, "blue")
    produces this result:

    And if we add a few more points:
       drawStar(canvas, 300, 200, 300, 9, "red")
    we get this result:



  3. drawSudokuBoard(canvas, board, margin, canvasSize) [70 pts] [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 is equal to both the width and 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: