CS 106 Winter 2017

Lab 05: Geometric context


Question 1 Dancers

In a series of exercises, you will use combinations of geometric context functions to draw different configurations of dancers. The goal is to do everything with geometric context functions. Every dancer will be drawn using shape( dancer, 0, 0 ), surrounded by suitable calls to pushMatrix(), popMatrix(), translate(), rotate(), and scale().

  1. Download the provided starter code. Navigate into the L05 folder and open the Dancers sketch.

  2. From the provided code, run the Dancers sketch. You'll see a single dancer in the centre of the sketch window:

    Press the space bar to cycle through a number of drawing "modes". You'll see that only Mode 0 is implemented, and the others display blank screens. You will write code for the other modes.

  3. Fill in the function drawMode1() so that it draws a 5×5 grid of dancers, as in the image below. All transformations must be based on the built-in functions translate(), rotate(), scale(), pushMatrix(), and popMatrix(). To draw each dancer, you must use shape( dancer, 0, 0 )no other arguments to shape() are permitted here, or in any of the other problems below!

    In this case, you'll want to use two nested loops, one in x and one in y (in either order). Inside the nested loops, translate, scale and draw a single dancer.

  4. Fill in the function drawMode2() so that it draws alternating upright and upside-down dancers, with their arms all pointing to the same side of the screen. Again, make sure that every dancer is drawn using shape( dancer, 0, 0 ). Remember that you can use the call scale( 1, -1 ) (inside a pushMatrix()/ popMatrix() pair) to flip a dancer upside-down.

  5. Fill in the function drawMode3() so that it draws a single large dancer near the middle of the sketch, with at least three smaller dancers perched on her. The smaller dancers must have their lower legs touching the large dancer, and must fit entirely in the sketch window. The image below gives one example.

  6. Fill in the function drawMode4() so that it draws a ring of eight dancers around the centre of the sketch window, each dancer rotated symmetrically:

    There are lots of different patterns that are correct solutions to this question, you don't have to copy the image here. What's important is that you have a ring of eight dancers twirling around the centre of the screen.

  7. Fill in the function drawMode5() so that it draws a ring of eight dancers around the centre of the sketch window, all standing upright:

    The ring should be roughly circular, and the dancers should all be pointing in the same direction. If you want, you can copy in the polar() function from the Advanced Shapes module, but that's just one option—it's quite possible to solve this question without that function. Another approach would be use a combination of rotate()-translate()-rotate() for each dancer.

Tips

Save your sketch, which should be named Dancers.

Submission

When you are ready to submit, please follow these steps.

  1. If necessary, review the Code Style Guide and use Processing's built-in auto format tool. You do not need to use the precise coding style outlined in the guide, but whatever style you use, your code must be clear, concise, consistent, and commented.

  2. If necessary, review the How To Submit document for a reminder on how to submit to LEARN.

  3. Make sure to include a comment at the top of all source files containing your name and student ID number.

  4. Create a zip file called L05.zip containing the entire L05 folder and all its subfolders.

  5. Upload L05.zip to LEARN. Remember that you can (and should!) submit as many times as you like. That way, if there's a catastrophe, you and the course staff will still have access to a recent version of your code.

  6. If LEARN isn't working, and only if LEARN isn't working, please email your ZIP file to the course account (see the course home page for the address). In this case, you must mail your ZIP file before the deadline. Please use this only for emergencies, not "just in case". Submissions received after the deadline may receive feedback, but their marks will not count.