Assignment 1

Assignment 1: Generative Art

Ryan Park (ryan.a.park@stanford.edu)

CS148 (Intro to Computer Graphics and Imaging)

January 18, 2007


This program draws five different images based around a set of hypocycloid parametric equations. (The equations were found on Wikipedia at http://en.wikipedia.org/wiki/Hypocycloid but the graphics are different than shown there.) It also draws a pentagon inside the curve, in a different color.

To use the program, press a number between 1 and 5, and it will draw the appropriate graphic. Dual framebuffers are used, but swapped regularly so that you can see the image as it's being drawn. When you're finished using the program, press Esc to exit.

Resposne to Instructor Questions

Question 1: In a GLUT program, how is control passed back to the programmer? How is this set up during initialization?

Control is passed back to the programmer through callbacks -- functions that are called on events like display/redisplay, keypress or window reshape. This is configured through methods like glutDisplayFunc() or glutReshapeFunc() which take a function pointer as a parameter.

Question 2: What does the parameter to glutInitDisplayMode() specify?

GLUT_RGBA says that we are use the Red-Green-Blue color model.

GLUT_DOUBLE syas to use double-buffering. It reads from one framebuffer while we write to a second, and then swaps those when we're done drawing the frame.

The | performs a bitwise OR, so that we create an int param that contains the bits for both the RGB and double-buffer constants.

Question 3: What do the calls to glOrtho() and glViewport() accomplish?

glViewport() sets the size of the drawable region inside the window -- in this case, it's the entire window.

glOrtho() sets the coordinate system that we use. As originally specified, it set the coordinates to go from 0 to 1 on both the X and Y axis. (I modified it to go from -10 to 10 instead.)

Together these parameters enable us to resize the window and have the image scale accordingly.