Course Home | Assignments | Class Photo | Computing Resources | Lab Hours/Tutoring | Schedule | Submit

Saint Louis University

Computer Science 150
Introduction to Object-Oriented Programming

Michael Goldwasser

Spring 2010

Dept. of Math & Computer Science

Hands-on Day

For Loops


All of these problems are for practice. You are freely encouraged to work together and you do not need to submit any of this work for a grade.


The book gives code for drawing a pyramid, with one rectangle per level (see /Public/goldwasser/150/book/ch04/pyramidLoop.py) It uses a geometric sketch (left) as a model, producing the final image (right) with a parameter controlling the size and number of levels.

A second version of the code (see /Public/goldwasser/150/book/ch04/pyramidNested.py) uses a nested loop to build the levels out of individual squares.

Our goal today is to create new patterns by either modifying those programs, or generate new ones.

Problems

  1. Instead of the basic pyramid, make a staircase rising to the right, with one rectangle per level

  2. Do the staircase but with many squares per level.

  3. Try to build a single Polygon object having a staircase shape.
  4. Try to build a brick wall using 3x1 ratio bricks
  5. Feeling really board? How about a brick walkway
  6. Here's some fun with colors. This figure is made up of thin vertical lines, each with a slightly different shade of magenta. Although we have typically been using names to specify a color, you can pick a custom color by giving an "RGB value", in the form of a tuple (red,green,blue), where those are intensity values from 0 to 255. For example setBorderColor( (255,0,255) ) gives you bright magenta. But we can use loop variables to vary the colors.
  7. And some final examples where we have covered the canvas with small squares and varied their colors along both axes.

Michael Goldwasser
CSCI 150, Spring 2010
Last modified: Tuesday, 02 February 2010
Course Home | Assignments | Class Photo | Computing Resources | Lab Hours/Tutoring | Schedule | Submit