CS430 Homework Assignment 2

Programming Problem:

1. The new commands you will be required to implement are:
    1.    x y moveto
    2.    x y lineto
    3.    stroke

moveto command simply moves the pen to a particular location without drawing anything.
The lineto command draws a line from the current position of the pen, to the point indicated.
The stroke command can be ignored in your program, but actually draws the line sequence in Postcript interpreters (eg. gv).

The following commands will draw two boxes.

%%%BEGIN
100 100 moveto
100 200 lineto
200 200 lineto
200 100 lineto
100 100 lineto
stroke

300 300 moveto
300 400 lineto
400 400 lineto
400 300 lineto
300 300 lineto
stroke
%%%END

You can assume for this assignment that a "moveto"/"stroke" pair defines a single closed polygon.

2. Modify your HW1 program to:

  1. Accept the "Moveto", "Lineto" and "Stroke" Postscript commands.
  2. Define the resolution of your output image to be 501 x 501.
  3. All the command-line options in Postscript commands implemented in HW1 should be supported, plus the following which implement viewport mapping. You should be able to process any subset of the options in any arbitrary order.
  4. [-j] The next argument is an integer lower bound in the x dimension of the viewport window (0)
  5. [-k] The next argument is an integer lower bound in the y dimension of the viewport window (0)
  6. [-o] The next argument is an integer upper bound in the x dimension of the viewport window (200)
  7. [-p] The next argument is an integer upper bound in the y dimension of the viewport window (200)
  8. The viewport coordinate system origin is in the lower left corner of your image. The X direction is to the right, and the Y direction is up.
  9. You may assume that the viewport parameters are greater than or equal to zero, and less then or equal to 500.
  10. Map the world window into the viewport.
  11. Clipping should occur along the outer boundaries of the viewport
  12. Perform polygon clipping (Weiler-Atherton).
  13. During clipping you may assume that none of the polygon edges overlap, and that no edges intersect at a vertex.
  14. Perform polygon filling (scan line algorithm, no flood filling).
  15. You can test your program with hw2.ps.
  16. The default option set for this assignment is equivalent to this command line.
        ./cs430_hw2 -f hw2.ps -a 0 -b 0 -c 250 -d 250 -j 0 -k 0 -o 200 -p 200 -s 1.0 -m 0 -n 0 -r 0 > out.xpm
  17. If the tester enters ./cs430_hw2 > out.xpm , the results should be the same as from the command line above, and produce the following image. Here is the XPM image file.
    PLEASE NOTE THAT THE BORDER IS NOT PART OF THE OUTPUT IMAGE. IT HAS BEEN PLACED AROUND THE IMAGE TO HIGHLIGHT THE POSITION OF THE VIEWPORT WITHIN THE WINDOW.

  18. Input/Output Example:
            i. Input: ./cs430_hw2 -f hw2.ps -a 0 -b 0 -c 500 -d 500 -j 0 -k 0 -o 500 -p 500 -s 1.0 -m 0 -n 0 -r 0 > hw2.xpm         ii. Output: Here is the XPM image file.

  19. Input/Output Example:
            i. Input: ./cs430_hw2 -f hw2.ps -a 110 -b 0 -c 410 -d 500 -j 0 -k 110 -o 500 -p 410 -s 1 -m 0 -n 0 - r 0 > hw2.xpm         ii. Output: Here is the XPM image file.

  20. Input/Output Example:
            i. Input: ./cs430_hw2 -f hw2.ps -a 10 -b 10 -c 500 -d 400 -j 10 -k 10 -o 500 -p 400 -s 1.2 -m 30 -n 20 -r 10 > hw2.xpm         ii. Output: Here is the XPM image file.



    3. Submission Guidelines:
        1. Assignments must be submitted via the 'submit' command located on the queen unix machine.
        2. README file: explaining at least the features of your program, language used, compiler or interpreter used, etc. Word documents will NOT be accepted.
        3. All source code. Your code must compile and run on the Solaris operating system (queen CS dept machine). The TA's will use this as the test platform.
        4. Binary executable named cs430_hw2
        5. Your program will be run by the TA's. Please do NOT submit any image files, Visual C++ project files, or anything not requested in this section.
        6. Makefile (optional but appreciated): have the default rule compile your program.

    NOTE: Your source code for all programming assignments will be run through a plagiarism detection system. This program uses compiler techniques which are invariant of syntax and style. If you are sharing code with other classmates, you will get caught. Please refer to the student handbook for actions that will be taken.


    Last modified on February 9, 2004.