Graphics Documentation

The graphics package requires that you copy three files, graphics.c, graphics.h, and Makefile from /home/mathcs/courses/cs246.

Structure of a Graphics Program.

A program using graphics must define a main function and a function

	  draw_window(graphics_context gc, int width, int height, void *data)
The main function must call the function
	  create_window(int width, int height, void *data)
This function creates a window into which you can draw. The width and height arguments give the initial size of the window (in pixels). The data argument is a pointer to arbitrary data. It is called by main.

The draw_window function draws in the window by calling drawing functions. The graphics_context argument to draw_window provides a connection to the window system. It is passes along as an argument to all of the drawing functions. The width and height arguments give the current size of the window. The data argument is a pointer to the data provided to create_window in main (if there is any).

The Drawing Functions

	void new_path(graphics_context gc)
Starts defining a path.
	void move_to(graphics_context gc, double x, double y)
Moves the current location to (x, y).
	void line_to(graphics_context gc, double x, double y)
Adds to the current path a line from the current location to (x, y).
	void relative_move_to(graphics_context gc, double x, double y)
Moves the current position x pixels to the right and y pixels down.
	void relative_line_to(graphics_context gc)
Adds to the current path a line from the current position to a new position x pixels to the right and y pixels down.
	void rectangle(graphics_context gc, double x, double y,
	                                    double width, double height)
Adds to the current path a rectangle whose upper left hand corner is (x, y) with the given width and height.
	void arc(graphics_context gc,
	         double x, double y, double radius,
	         double start_angle, double end_angle)
Adds to the current path an arc whose center is at (x, y) with the given radius. The arc extends from angle start_angle to angle end_angle. The angles are measured in radians from the positive x-axis.
	void stroke(graphics_context gc)
Strokes the current path.
	void fill(graphics_context gc)
Fills the interior of the current path.
	void close_path(graphics_context gc)
Closes the current path by adding a line from the current position to the beginning point of the path.
	void text(graphics_context gc, char *string)
Strokes the given text at the current location.
	void set_font(graphics_context gc, char *font)
Sets the font face for text to the given font name. Names that are guaranteed to work are serif, sans-serif, and monospace.
	void set_font_size(graphics_context gc, double size)
	void color(graphics_context gc, double r, double g, double b)
Sets the color to the given intensities for red, green, and blue. These must be numbers between 0 and 1. 0 is low and 1 is high. Thus 0, 0, 0 is black and 1, 1, 1 is white.

Graphics Demo Program

Graphics Grid Program

Makefile