Using SpelGraph

 

SpelGraph is a graphics library based on Allegro. It enables students to learn how graphics are placed on the screen in the way that video games, GUIs, and other graphics oriented applications may accomplish their tasks. This library is a simple library to allow class discussions about fundamental concepts.

 

A SpelGraph Program Template

 

A SpelGraph program is based on the following template:

 

#include "SpelGraph.h"

 

int main() {

 

  initSpelGraph();

 

  // Graphics commands would go here

 

  finishSpelGraph();

 

  return 0;

}

END_OF_MAIN();

 

SpelGraph Commands

 

The SpelGraph Commands are listed in this section as a table. Gives the name and meaning for each function.

 

Function/Command

Its Meaning?

void initSpelGraph()

Initializes the program. This must be done before any graphics functions are used. (typically at the beginning of main)

void finishSpelGraph()

Prepares the program to end. This must be done after all graphics functions have executed.(typically at the end of main)

void END_OF_MAIIN()

Also helps with closing the graphics program. Must be placed after the main function (note that it is after the last ‘}’).

int getmaxx()

Returns the maximum x coordinate

int getmaxy()

Returns the maximum y coordinate

void lineto(int x, int y)

Draws line from current pen position to position (x,y). The (x,y) become the new position of the pen

void moveto(int x, int y)

Positions the pen at position (x,y). does not draw.

void circle(int x, int y, int radius)

Draws a circle where the center is at (x,y) and it has a radius of size radius. The edge of the circle is based on the current color.

void rectangle(int x1, int y1, int x2, int y2)

Draws a rectangle where the upper-left corner is (x1, y1) and the lower-right corner is (x2, y2). The edge of the rectangle is based on the current color.

void fillcircle(int x, int y, int radius)

Draws a circle as with the ‘circle’ function, but fills in the circle with the current color.

void fillrectangle(int x1, int y1, int x2, int y2)

Draws a rectangle as with the ‘rectangle’ function, but fills in the rectangle with the current color.

void getmouse(int& x, int& y)

Returns the coordinates of the last mouse click as x and y.

void writedraw(string s, int x, int y)

Draws the string s at the position of (x,y) (relative to the first character in the string)

void writedraw(int i, int x, int y)

Draws the integer i at position (x,y).

void delay(int ms)

Makes the program pause for ms milliseconds (1 sec = 1000 ms).

void setcolor(color c)

Sets the current color to be used by all other drawing functions. Colors can be:

BLACK, DBLUE, DGREEN, DCYAN, DRED, DMAGENTA, ORANGE, GRAY, DGRAY, BLUE, GREEN, CYAN, RED, MAGENTA,             YELLOW, WHITE

void clearscreen(color c)

Erases the screen and sets the screen color to c. Uses the same colors as in setcolor.