CS 151: Project #11

Project 11: Non-Photorealistic Rendering

Main course page

For the assignment, you'll need to implement two more styles of drawing in the Transformer class. To implement a new style, you just need to add another case to the if statement in the forward method of the Transformer class.

For example, you could implement a 'randomcolor' style by making a case that sets the color to a random value before calling the turtle.forward function. (If you look in my transformer.py file at the 'L' case you'll see how to save and restore the original color of the turtle.

The last step in the project is to enhance your scene from the last project by making use of the various styles you implement this week. You should be able to run the scene with different styles using minimal changes to the code.


Tasks

  1. Implement a style 'broken' that draws the line segment as two jittered line segments. The implementation is similar to the 'jitter' case, but instead of drawing one line, you draw two. One line goes from the jittered start point to a jittered midpoint, the second line goes from another jittered midpoint to the jittered final point. The midpoint of the line segment is:

    (xm, ym) = ( (x0 + xf)/2, (y0 + yf)/2 )

    Once you have the midpoint, creating two jittered lines is simple.

    # Go to (x0 + jx, y0 + jy)
    # Put the pen down
    # Go to (xm + jx, ym + jy)
    # Pick the pen up
    # Go to (xm + jx, ym + jy)
    # Put the pen down
    # Go to (xf + jx, yf + jy)
    

    Note that for each goto statement, the jx and jy values should be regenerated from a Gaussian distribution with a zero mean and jitterSigma as the standard deviation. They should not all be the same.

    Make a scene with three copies of the systemA L-system showing it drawn in 'normal', 'jitter', and 'broken' style. Use 2 iterations for the L-system. Make a separate file with your scene function within it. Do not put the code for your scene in any of the files that define classes (Transformer, Lsystem, Shape, etc).

    Grab a screen shot of your scene and include it in your writeup.

  2. Create a 'dash' style that draws straight, but does not draw a solid line. Do not hard code the dash length. Instead, create a field in the Transformer init to hold the dashLength. You'll also need a dash method in the Transformer class and a setDash method and associated dash field in the Shape class, just as we did with the style and jitter information.

    Generate a collection of simple shapes (not trees) that show the 'dash', 'normal', 'jitter', and 'broken' drawing modes. Your writeup should be able to point out which are which. As above, make a separate file to generate your scene.

    Grab a screen shot of your scene and include it in your writeup.

  3. Make a copy of your scene code from last week and put it in a new file. Edit your scene so that it makes use of the different drawing styles. Feel free to enhance it, but focus on enhancements that make use of the different drawing styles and shape classes you've created. When you're done, you should have something that looks a bit more like a real painting.

    Grab a screen shot of your scene and include it in your writeup.

Extensions

  1. Make a new interesting scene that demonstrates various aspects of the system and makes good use of loops or other control structures. Be sure to point these out in your writeup.
  2. Generate aggregate object classes that draw several, possibly different shapes. Aggregate shape classes will generally include their own init method and draw method.
  3. Add other drawing styles. For example, try making one that simulates a brush by drawing many approximately parallel lines. Slight variations in color between the different lines makes the effect better. You might also try a pen-and-ink style with cross-hatching or just a series of straight lines at an angle to the direction of the actual line.
  4. See if you can make use of the fact that the turtleUtils.py file contains a function that can catch mouse clicks.

Code Handin

Hand in your code for this assignment using the Moodle drop box. There will be a drop box for each week's assignment. Hand in your python code file. If there are any specific images required for your system to work, zip them up with your code file.

Please do not place code anywhere public. Do not include it in your writeups on the wiki, for example.

Writeup

Each of you should create your own wiki page for your writeup. The writeup can be brief, but should include the following components.

  1. A brief abstract (200 words or less) describing the project.
  2. A more detailed description of what you did. This week, focus on how encapsulation of the details made it fairly easy to change drawing styles. Also, comment briefly on how information stored with the shape object gets passed along to the Transformer appropriately.
  3. Include any images or other output your program created. For this project, include screen captures of your scenes.
  4. Describe any extensions you implemented and show results for them.
  5. Give a brief (1 paragraph) description of what you learned.

Colby Wiki

Please put the label cs151s09proj11 on your writeup page (down below the editing window on the edit tab). Please make sure you type the label exactly as given above.