Lab Module G -- Painters: graphics and higher order abstractions.

CISC 280 Program Development Techniques

This module is a two week unit and constitutes the first of two programming projects. It counts for 8% of the grade (one module and one half of the project credit). Only exercise 1 is due in lab on Monday, April 2. The rest is due on April 9. There will be no Module G topping exercise in lab on April 2. Thus April 2 is a good opportunity to make up topping off exercises for previous modules, if not yet completed. This is also a good lab to get design and debugging help on the painter graphics.

Goals:

  1. Gain further experience of the powers of abstraction levels -- doing so in a graphical context where the output visually reflects the programming effort.
  2. Gain familiarity with some transformational principles used in computer graphics.
  3. Design some aesthetically pleasing pictures.

Reading: SICP (Structure and Interpretation of Computer Programs), Section 2.2.4
Code on composers: ~saunders/280/graphics/painters.scm.
The command: drscheme ~saunders/280/graphics/painters.scm
will start scheme with the painter code loaded. Otherwise you can open it from the file menu. The summary lists most of the procedures defined in the painter system.


Homework exercise:

Painter project

(due at start of lab on 9 Apr 2001.)
  1. Write a painter that consists of your painter from exercise 1 done 24 times in an 4 by 6 grid. Twenty three of the copies should be right-side-up and exactly one should be rotated 90 degrees (left or right). You can place the rotated copy anywhere in the interior of the frame. That is don't make it one of the copies that touches a side of the overall frame. So the pattern is like this:
    UUUUUU
    UUUUUU
    UUCUUU
    UUUUUU
    
  2. Write Painter operator stack.

    (stack p:painter n:positive-int) -> q:painter

    We will use the notation "x:t" to indicate that the argument x is supposed to be of type t. The output of stack is a painter q, where (q f:frame) will draw a stack of p's in frame f. Painter q will paint n copies of p along the bottom 1/n of f, n-1 copies centered on the next level, and so on, until the top of the n levels has one copy of p centered. Something like this:

        p
       p p
      p p p
     p p p p
    p p p p p 
    
    Illustrate on

  3. Let UPO stand for "unary painter operator". A UPO takes a painter as argument and returns a painter. For example, flip-vert is a UPO. Let BPO stand for "binary painter operator". A BPO takes two painters as arguments and returns a painter. For example, beside is a BPO. Write a higher-order operator which takes one or more UPO's and/or BPO's among it's arguments and returns a UPO or BPO. The higher-order operator square-of-four is a model for this exercise. It takes 4 UPO's and returns a UPO. You can be creative as to what your higher order operator does. It is acceptable for it to take some lower order arguments such as painters or numbers as well as one or more UPO's or BPO's. For example, a higher-order operator might have this signature:
    (wheel-of-four top-left:UPO top-right:UPO bottom-left:UPO bottom-right:UPO center:painter) -> output:UPO
    such that, for the frame divided into 9 segments as
    123
    456
    789,
    
    The output UPO takes a painter p and paints (top-left p) spread over positions 1&2, paints (top-right p) in 3&6, paints (bottom-right p) in 8&9, paints (bottom-left p) in 4&7, and paints center in 5.

    Use your imagination and cook up something you'll enjoy.


Here is a way to print a graphics window in unix (for submitting the result):

  1. enter "xv".
  2. pop up the "xv controls" window by clicking right button on the xv window.
  3. click the "Grab" command.
  4. Click left button on the window to be captured. Note: this
  5. click will NOT destroy a painter window, the next click will.
  6. Return to "xv controls" and select "Print".
  7. Finally, select "Quit" on the xv controls to exit xv.

Module G Flourishes (optional problems):

  1. Project flourish: Write additional higher-order operator(s) like the one for part 3 above.

Summary of data types used in painter system

Types: Summary of the procedures used in the painter module and defined (except where *starred) in the text.
  • Vect operators( add-vect, sub-vect, scale-vect):
  • Segment primitives ( make-segment, start-segment, end-segment):
  • Frame primitives ( make-frame, origin-frame, edge1-frame, edge2-frame, frame-coord-map):
  • Viewport primitives: See Dr Scheme online help if interested in more features of viewports (windows).