CMU 15-112: Fundamentals of Programming and Computer Science
Collab 3 (Due Monday 21-Sep at 8pm ET (Pittsburgh-time))




  1. Standard problems You will work with your partner (or partners) to solve as many of these problems as possibe within the time limit. Your TA will make sure that at least one team from your group is working on each problem. Comment out the test cases for problems you are not solving to make it easier to run your drawings. Note: We hope you will finish one of these within the allotted time, or perhaps even two, but you you will not be graded on completion. Your code must demonstrate effort, however, and your TA should be able to see you have collaborated well.

    1. drawPattern2(points, canvas, width, height)
      Write the graphics function drawPattern2(points, canvas, width, height), that draws this pattern using only lines:
              
        
      runDrawPattern2(4, 200, 200)
        
      runDrawPattern2(5, 200, 200)
        
      runDrawPattern2(10, 400, 200)

      Notes:
      • points is the number of points along each axis in one quadrant (including the center and the endpoint).
      • Hint: Think of this as an x and y axis. Now, look only at the first (top-right) quadrant. See that as we move down the y axis, we move right across the x axis. We draw a line from each point on the y axis to the corresponding point on the x axis as we go. In this way, the lines start mostly vertical and end mostly horizontal. Think about it! Then do the same basic idea for the other 3 quadrants.
      • The pattern should fill the canvas (so it must be based on the width and height parameters).
      • The starter file includes functions to run the drawing with different parameters, but there is no autograder! Instead, ask yourself if it looks right.
      • There are many reasonable ways to solve these exercises! We also hope you'll add some nice color.

    2. drawPattern3(points, canvas, width, height)
      Write the graphics function drawPattern3(points, canvas, width, height), that draws this pattern using only lines:
              
        
      runDrawPattern3(4, 200, 200)
        
      runDrawPattern3(5, 200, 200)
        
      runDrawPattern3(10, 400, 200)

      Note:
      • points is the number of points along each side
      • The pattern should fill the canvas (so it must be based on the width and height parameters).
      • The starter file includes functions to run the drawing with different parameters, but there is no autograder! Instead, ask yourself if it looks right.
      • There are many reasonable ways to solve these exercises! We also hope you'll add some nice color.



    3. drawFancyWheels(canvas, width, height, rows, cols)
      Write the function drawFancyWheels(canvas, width, height, rows, cols) that draws a rows-by-cols grid of so-called "fancy wheels" according to the rules below. First, though, for some context, here is the result of calling drawFancyWheels(canvas, 900, 600, 4, 6), scaled here to half-size (50%):


      With that, here are the rules to follow. It may help to refer to the picture above as you go:
      1. Think of the drawing as in a grid. Each entry in the grid is a "cell". So the drawing above is a grid with 4 rows, 6 columns, and 24 total cells.
      2. The width of each cell is the total width of the canvas divided by the number of columns. The height similarly depends on the number of rows.
      3. We found it very helpful to use a helper function for each cell drawFancyWheel(canvas, cx, cy, r, n, color). Here, (cx, cy) is the center of the wheel, r is its radius, n is the number of points around the wheel, and color is of course its color.
      4. The radius r of each wheel depends on the smaller of the cell width and cell height. Divide this by 2 to convert from diameter to radius. Then, multiply it by 90% so the wheels do not quite entirely fill each cell.
      5. The number of points n in each wheel depends on the row and the column of the wheel. The top-left wheel should have 4 points, then each wheel on the next diagonal (heading to the up-right) has 1 more point than the wheels on the previous diagonal. Look closely at the picture above to help clarify this.
      6. The color of each wheel is made up of red, green, and blue components, like so:
        • The red component is 0 (entirely off) in the top row, and 255 (entirely on) in the bottom row, and varies linearly in between.
        • The green component is 255 in the left column, and 0 in the right column, and varies linearly in between.
        • The blue component is always 0.
        Note that you may find the rgbString function in the course notes to be helpful here. Also, note that the bottom-left wheel is yellow, becuase the RGB value of yellow is (255, 255, 0), and the top-right wheel is black, because the RGB value of black is (0, 0, 0).
      7. A wheel is made up of only two kinds of shapes -- a circle and some lines.
        • Each wheel includes one circle, which is drawn using the radius r of the wheel.
        • Each wheel contains n points, but these points are not ever drawn. They are only used as endpoints for the lines. That said, one point is always straight up (at 90 degrees, mathematically), and the rest are evenly distributed around the wheel.
        • To draw a wheel, draw the circle and then draw one line for each pair of points around the wheel. Thus, each wheel includes n*(n-1)//2 lines. So if n==4 for example, the wheel include 4*3//2==6 lines.
      8. As you resize the graphics window, the size of the wheels will adjust, but everything else remains the same -- same number of rows and columns, same colors, and so on.

      Finally, to be clear, here is the result of calling drawFancyWheels(canvas, 400, 600, 1, 1) again scaled to 50%:


  2. Discuss solutions to Standard Problems
    Like in collab2, TAs will lead a discussion where you and your teammate(s) will present your work on the standard problems we gave you above. Your TA will be grading you based on demonstrated effort and good collaboration, so participate!



  3. Code tracing discussion
    1. Discuss these questions:
      1. What strategies do you personally use to solve code-tracing problems?
      2. What makes a "good" code-tracing problem?
    2. Help your TA write a new code-tracing problem
    3. You are graded on attentiveness and courtesy. (In other words, pay attention and be respectful.)



  4. Create a new CT problem
    With your partner(s), choose a topic from the strings notes (like slicing or looping through characters). Now, write a CT that uses that concept in an important way (though it can use others as well). Add a screenshot of your CT to the google doc shared by your TA. (The screenshot keeps others from easily running your CT and spoiling the answer.)
    Your CT should neither be easy nor extremely difficult. It should require the solver to understand the concept you chose in order to solve it. If you finish one, make another!
    Put your CT(s) into your collab3.py file underneath the standard problems, as indicated by the comment line.



  5. Solve new CT problems
    Your TA will select some of the CT problems made by the group and you will each have a few minutes to work out the answer. When solving the CTs, you may work individually on paper, but then you should participate in volunteering answers and discussing the problems. (Don't simply copy and run the code in Python; that's not helpful.)
    After the collab, we encourage you to try solving some of the other CTs made by your group, but we will not collect any solutions to group CTs.



  6. Stylish Scavenger Hunt
    Important: If your group does well here, you will not lose any style points on HW3a or HW3b!
    Your TA has downloaded your latest hw3a submissions from Autolab. Your goal, as a single group, is to discover and correct instances of style violations from as many of the 12 violation categories as possible (see below). If you are comfortable with sharing, you may volunteer your code for style critique. Then your TA will screenshare a problem from the submission (so you can't just quickly add in new style errors!).
    Now, anyone in the group can point out a) where the violation is, b) what kind of violation it is, and c) how it can be fixed. Your TA will keep track of which categories have been covered. Note:
    • You will not lose style points on hw3 if your group finds at least one example from each category of style violation below (and in the style notes)
      1. Ownership
      2. Comments
      3. Helper Functions
      4. Variable Names
      5. Unused Code
      6. Formatting
      7. Test functions
      8. Repetitive Code
      9. Magic Numbers
      10. If/Else Statements
      11. (You do not have to find examples of global variables or inefficiency)
    • You must also individually participate (point out a bug, ask a question, etc.) to get the benefit (since it wouldn't be fair if you didn't try to help the group).
    • We will only be looking at certain hw3a problems to avoid distributing certain answers. Your TA will tell you which ones.
    • If you finish very very early, keep trying to find more style errors. This demonstrates effort to your TA.
    • You do not have to volunteer your submission if you are not comfortable with it, but we encourage you to, since it will help ensure that nobody gets style deductions. Everyone will have mistakes, so don't be embarrassed!
    • Be respectful, of course. Remember that you're working towards a common goal and you are not in competition with anyone.


Did you finish early?
Take some time to get to know your fellow students!




SUBMIT TO AUTOLAB!
Note the submission deadline at the top of the page. You must submit to autolab by that time. The time is in ET (Pittsburgh time). We strongly recommend you submit immediately after your group is finished! No work will be accepted after the deadline (unless of course your collab meeting is after the deadline).
Submit collab3.py to Autolab (Note: this is a python file, not a zip file like last week!). Your collab3.py should contain:
  1. Your work on the standard problems.
  2. At least one CT created by you and your partner(s)

(It is ok if you did not finish the standard problems, and it is ok if your file does not run. You are graded on demonstrated effort during the 3-hour session, and your submission should provide extra evidence of that effort. There is no autograder. You do not need to submit solutions to the CT problems made by other group members.)

If you realize you messed up your submission (i.e. submitted a blank file, zip file, etc) you can submit up to 5 times, but you really ought not need to.

Remember, no late work is accepted! Uploading to autolab takes a few minutes at most. Do not wait until the deadline and risk getting a zero.