Computer Languages History
(Click or use local copy.)
 CS 3723/3721
 Programming Languages
 Fall 2004

 Recitation 12
 Postscript Programs
    Week 12: Nov 8-12
 Due (on time): 2004-11-15  23:59:59
 Due (late):        2004-11-19  23:59:59

Special Note: I screwed up the submission program, and then wasn't able to read my email last night (Monday), so those of you that tried to submit were not able to. A number of you emailed me this recitation. I'll insert these emails myself and count them as on time, and submissions will be "on time" until Wednesday morning before class. Sorry for this confusion.

I now also understand the question about the PDF not updating, and this is described in the last question at: Questions

Recitation 12 must be submitted following directions at: submissions with deadlines
  • 2004-11-15  23:59:59 (that's Monday, 15 November 2004, 11:59:59 pm) for full credit.
  • 2004-11-19  23:59:59 (that's Friday, 19 November 2004, 11:59:59 pm) for 75% credit.


Postscript program: a general "star" program: You are to write a Postscript program that will produce any of a variety of "stars", similar to the ones given below:


Detailed Requirements: Your program should conform the the following requirements:

  1. Create the star centered at the origin.
  2. Translate the center of the star to the exact center of the page before rendering it.
  3. The radius of the star should be exactly 100 points.
  4. The star should have two input parameters on the stack: n, the number of star "tips", and m, the number of tips to skip over in drawing a line. Thus the four stars above have parameters (left-to-right and top-to-bottom) 5 2, 10 3, 20 6, and 20 9.
  5. You must use a for loop (or some other loop), so that your program will work for any reasonable input. (You don't need code to verify "reasonable input".)
  6. If you use code that you get from some other source (wherever it might be from: the web, textbooks, my own materials, or another student), then you must cite this source in the code that you submit.


Hints: Here are a few hints:

  1. Don't try to mimic the star program presented in the course and in the text. That one is very tricky.
  2. Don't try to do the star as a single path, but just draw each line, one at a time.
  3. Calculate the tips of the star, using simple equations, so that (100, 0) can be one tip, and locations of the others depend on how many there are (divide 360 by n to get the angle between tips), and then use simple formulas (involving sin and cos) for the locations of other tips.
  4. After drawing one line, one simple method (but by no means the only one), is to use rotate by the angle between tips to get the other lines.
  5. Any use of translate or rotate (or any other change of the graphics state) enclosed inside the Postscript commands gsave and grestore will not have an effect outside these enclosed commands. So you can do a rotate after gsave, do some other stuff, and then after a grestore the effect of the rotate is reversed. This use of gsave and grestore is illustrated and explained at the end of the "star" example: Star


What you should submit: In the normal way you should submit the Postscript source for the required star program:

Then in the next class meeting: Wednesday, 17 November 2004 (or under my door) submit actual computer printouts containing:

  1. Postscript source of the program.
  2. Pictures of runs for the cases above along with one other case using a larger value of n of your choosing.


Revision date: 2004-08-01. (Please use ISO 8601, the International Standard Date and Time Notation.)