Reference Manual

Home ] Introduction ] Installation ] Basic Lessons ] Just Enough C++ ] Advanced Lessons ] [ Reference Manual ] Packages ] Demos ]

 

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

[GrafiX Home]   [draw functions]   [get_functions]   [set functions]   [named colors] [ named points]

Welcome

The GrafiX reference manual can be thought of as an annotated version of the header file grafix.h, providing prototypes of functions and definitions of classes, as well as explanation and examples.  Often further description is provided in one of the lessons.  Hopefully the reader knows that given a prototype such as

void draw_circle(int x, int y, int r);

the user is not expected to type the above literally, but to provide a specific integer x, integer y, and integer r as in

draw_circle(100, 100, 50);

If that is not obvious to you, then you might find this reference manual a bit frustrating and want to start with the basic lessons.

Only the GrafiX core is included here.  See elsewhere for documentation of Packages.

Alphabetical list of GrafiX commands

ANIMATE(duration_in_seconds, repeat_status)

Not truly a function, but a #define macro, ANIMATE is the key to nearly effortless animations.  The programmer sets a time and uses true or false to indicate whether the animation should restart when this time has elapsed.  ANIMATE needs a body, enclosed in braces, which defines a general frame of the animation.  Typically the range function returns varying values used to set positions, colors, and other drawing properties.  For example, the following animates a circle of radius 100 once across the middle of the screen, blending from red to green in 6 seconds.

ANIMATE(6, false)
{
   set_color( range(RED, GREEN) );
   draw_circle( range(0, MaxX), MidY, 100 );
}

bool animation_between(int start_percent, int stop_percent);

Returns true if the current animation is between the indicated percents, expressed from 0 through 100.

void animation_end();

Causes the current animation to end.  It is important not to break out of an animation loop without properly ending the animation.

int animation_percent();
double animation_proportion();

Return the progress through the current animation either as a percent 0 through 100 or as a proportion 0 through 1.

double circle_angle(int x, int y, int rayPt_x, int rayPt_y);
double circle_angle(Point center, int rayPt_x, int rayPt_y);
double circle_angle(int x, int y, Point rayPt);
double circle_angle(Point center, Point rayPt);

Returns the angle from a center to another point.  The angle is measure in degrees with 0 degrees to the right and positive angles increasing counter-clockwise.

Point circle_point(int x, int y, int r, int angle);
Point circle_point(Point center, int r, int angle);
Point circle_point(int x, int y, int r, Point ray_point);
Point circle_point(Point center, int r, Point ray_point);

Returns the point on a circle at a given angle or in a given direction.  For example, the following draws a point on a circle centered in the screen with a radius of 100 that is 45 degrees counter-clockwise from "east".

draw_point( circle_point(MidPt, 100, 45 ) );

The following draws a point on the same circle that is in the direction of a ray from the center of the circle to the lower-right corner of the screen.

draw_point( circle_point(MidPt, 100, MaxPt) );

void close_window();

This function is called automatically by the GrafiX environment to perform shut-down chores.  You probably shouldn't be calling it yourself.

class Color
{
public:
//Data Members
   int r, g, b;

  
  
public:
//Constructors
   Color(){r = 255; g = 255, b = 255;}
   Color(int red, int green, int blue);
//Methods
//These two functions return a darkened/lightened copy of a Color.
//Given Color c(100, 200, 255), then c.darken(50) returns a Color 
//that is 50% of the way from c to BLACK, or r=50, g = 100, b = 127.
   Color dark (int percent = 50); //returns a color darkened by 0-100 percent
   Color light(int percent = 50); //returns a color lightened by 0-100 percent

   Color inverse(); //returns the inverse of the Color
};
bool operator==(Color& lhs, Color& rhs);
bool operator!=(Color& lhs, Color& rhs);

For details about the methods of the color class, click here.

Colors and their RGB values

The 16 "HTML" colors

AQUA ( 0, 255, 255) is the same as CYAN
BLACK ( 0, 0, 0)
BLUE ( 0, 0, 255)
FUCHSIA (255, 0, 255) is the same as MAGENTA
GRAY (128, 128, 128)
GREEN ( 0, 128, 0) (note that this is not "full" green, which is LIME).
LIME ( 0, 255, 0)
MAROON (128, 0, 0)
NAVY ( 0, 0, 128)
OLIVE (128, 128, 0)
PURPLE (128, 0, 128)
RED (255, 0, 0)
SILVER (192, 192, 192)
TEAL ( 0, 128, 128)
WHITE (255, 255, 255)
YELLOW (255, 255, 0)

The following colors should be available on any Windows system.  If an RGB value is specified that is not available, Windows chooses a nearest color or uses "dithering", which may not give the desired color.  Safe colors use hexadecimal values of 33 (decimal 51), 66 (102), 99 (153), CC (204), and FF (255).

BRICK_RED (204, 0, 0)
BROWN (102, 51, 0)
CHOCOLATE (204, 102, 0)
CYAN ( 0, 255, 255) is the same as AQUA
FLESH (255, 204, 153)
GOLD (204, 153, 0)
GREY (128, 128, 128) is another spelling of GRAY
OLIVE_DRAB (153, 153, 102)
ORANGE (255, 102, 0)
MAGENTA (255, 0, 255) is the same as FUCHSIA
PINK (255, 0, 102)
ROSE (255, 0, 153)
SALMON (255, 153, 153)
SKY_BLUE ( 51, 153, 255)
TAN (255, 204, 102)
VIOLET (102, 0, 255)

//Other Colors in the Windows minimal 16 color palette
#define
DARK_BLUE Color( 0, 0, 128) //also NAVY
#define
DARK_RED Color(128, 0, 0) //also MAROON
#define
DARK_MAGENTA Color(128, 0, 0) //also PURPLE
#define
DARK_YELLOW Color(128, 128, 0) //also OLIVE
#define
LIGHT_GRAY Color(192, 192, 192) //also SILVER

//Other Colors in the Windows reserved 20 colors
#define
MONEY_GREEN Color(192, 220, 192)
#define
LIGHT_SKY_BLUE Color(166, 202, 240)
#define
CREAM Color(255, 251, 240)
#define
MEDIUM_GRAY Color(160, 160, 164)

template <typename S, typename T>
void copy_array(S* s, T* t, int n)
{
   for(int i = 0; i < n; i++)
   t[i] = s[i];
}

The templated copy_array function will copy the elements from array s into array t as long as there is a conversion between the two.  A typical use might be to convert an array of VariablePoints (see Variable Package) to an array of Points for use in a call to draw_polygon() or draw_bezier() as in the following

VariablePoint vPts[8];
Point Pts[8];
copy_array(vPts, Pts, 8);

Copy functions note:

NOTE: Animation speed can be greatly affected by the color settings of the computer.  Lower color depths generally improve speed.  Right-click on the desktop, select Properties, then the Settings tab.  16-bit color works well if it is available.  256-color mode gives the best performance.  24- and 32 bit color might perform poorly.  The copy_page function is responsible.  It takes longer to copy when there is a greater color depth.

void copy_block(Point left_top_src, Point right_bottom_src, Point top_left_dest, int src_page = -1, int dest_page = -1);

A rectangular block specified by the first two points is copied to the third point specified.  By default if the last two parameters are omitted, then copying is done on the active page.  Otherwise, we can copy between pages.

void copy_block_stretch(Point left_top_src, Point right_bottom_src, Point left_top_dest, Point right_bottom_dest, int src_page = -1, int dest_page = -1);

This behaves like copy_block except that the fourth point parameter allows us to distort the rectangular region being copied.  Note that the destination points need not have the "left_top" above and to the left of the "right_bottom"; in other words, with appropriate choices of the destination points we can flip an image horizontally and/or vertically.

void copy_buffer_to_screen();
void copy_buffer2_to_buffer();
void copy_buffer2_to_screen();
void copy_page(int src_page, int dest_page);

These allow us to copy entire pages to other pages.

Point cursor_point();

Returns the current cursor point.  I often use the CurPt macro instead.

Point cursor_point_rescaled(int x, int y, int rx, int ry);
Point cursor_point_rescaled(Point center, int rx, int ry);
Point cursor_point_rescaled(Point left_top, Point right_bottom);

These functions rescale the entire screen to fit into another rectangle in such a way that the point returned is the point of the rectangle in the same relative position as the cursor point is in the screen.  There are three different ways to specify the rectangle: center coordinates and radii, center point and radii, or corner points.

int cursor_x();
int cursor_x_rescaled(int low, int high);
double cursor_x_rescaled_continuous(int low, int high);
int cursor_y();
int cursor_y_rescaled(int low, int high);
double cursor_y_rescaled_continuous(int low, int high);

I use CurX and CurY macros instead of cursor_x() and cursor_y().  The rescaled versions allow us to identify the low value with one end of the screen and the high value with the other end of the screen and obtain the correctly scaled intermediate value.  This can be surprisingly useful when hooked up to a parameter within an animation loop.  The continuous version return decimals whereas the non-continuous version returns integers.  For example, cursor_x_rescaled(0,10) would return a value of 0 through 10 depending on which of the 11 (yes, 0 through 10) equally spaced vertical strips the cursor is in.  Using cursor_x_rescaled(0,1) would tell us if the cursor were in the left or right half of the screen depending on whether a 0 or 1 were returned.

void delay(int millisecs);

The computer takes a nap.  This function may not be reliable below 55 milliseconds due to the way the Windows clock works. 

double distance(int x1, int y1, int x2, int y2);
double distance(Point p, Point q);
double distance(int x1, int y1, Point q);
double distance(Point p, int x2, int y2);

Returns the distance between two points.

double distance(Color c1, Color c2);

Returns the distance between two colors using the Euclidean metric in RGB 3-space.  The farthest possible distance, say between black and white, is 441.673.  The distance from pure red to pure blue is 360.624.  The distance between black and either of red or blue is 255.0.

void draw_arc(int x, int y, int r, int start_angle, int stop_angle);
void draw_arc(Point center, int r, int start_angle, int stop_angle);
void draw_arc(int x, int y, int r, Point start_point, Point stop_point);
void draw_arc(Point center, int r, Point start_point, Point stop_point);

void draw_arc_filled(int x, int y, int r, int start_angle, int stop_angle);
void draw_arc_filled(Point center, int r, int start_angle, int stop_angle);
void draw_arc_filled(int x, int y, int r, Point start_point, Point stop_point);
void draw_arc_filled(Point center, int r, Point start_point, Point stop_point);

void draw_arc_3D(int x, int y, int r, int start_angle, int stop_angle);
void draw_arc_3D(Point center, int r, int start_angle, int stop_angle);
void draw_arc_3D(int x, int y, int r, Point start_point, Point stop_point);
void draw_arc_3D(Point center, int r, Point start_point, Point stop_point);

void draw_arc_3D_filled(int x, int y, int r, int start_angle, int stop_angle);
void draw_arc_3D_filled(Point center, int r, int start_angle, int stop_angle);
void draw_arc_3D_filled(int x, int y, int r, Point start_point, Point stop_point);
void draw_arc_3D_filled(Point center, int r, Point start_point, Point stop_point);

void draw_arc_P3D(int x, int y, int r, int start_angle, int stop_angle);
void draw_arc_P3D(Point center, int r, int start_angle, int stop_angle);
void draw_arc_P3D(int x, int y, int r, Point start_point, Point stop_point);
void draw_arc_P3D(Point center, int r, Point start_point, Point stop_point);
void draw_arc_P3D_filled(int x, int y, int r, int start_angle, int stop_angle);
void draw_arc_P3D_filled(Point center, int r, int start_angle, int stop_angle);

The above overloads draw circular arcs.

void draw_bezier(Point begin, Point c1, Point c2, Point end);
void draw_bezier(Point* all_points, int array_size);
void draw_bezier(Point* pts, int num_points, Point* c1, Point* c2);
//This next determines most initial control points of a poly-bezier from the previous
//second control point so that the pair and the intermediate endpoint are collinear.
//This results in differentiable curves at the joins.
void draw_bezier(Point* pts, int num_points, Point c1, Point* c2, int percent = 100);

See Advanced Lessons - Bezier Curves for details.  The first form draws a single Bezier curve given its endpoints and control points.  The next two forms allow for n joined Bezier Curves, specifying a total of 3n points either as a single array or broken down into endpoints and control points.  The last form will calculate the first control point of every curve past the first one in such a way that a line connecting a first control point of a curve with the second control point of the previous curve passes through the point connecting the two curves.  This ensures that the curve will be smooth at the joining point.  The optional percent parameter determines how far from the join point the calculated control point will be with the default being 100% as far as the previous control point is from the join point.

void draw_circle(int x, int y, int r);
void draw_circle(Point center, int r);
void draw_circle_filled(int x, int y, int r);
void draw_circle_filled(Point center, int r);

void draw_circle_3D(int x, int y, int r);
void draw_circle_3D(Point center, int r);
void draw_circle_3D_filled(int x, int y, int r);
void draw_circle_3D_filled(Point center, int r);

void draw_circle_P3D(int x, int y, int r);
void draw_circle_P3D(Point center, int r);
void draw_circle_P3D_filled(int x, int y, int r);
void draw_circle_P3D_filled(Point center, int r);

The above overloads draw circles.

void draw_ellipse(Point left_top, Point right_bottom);
void draw_ellipse(int x, int y, int rx, int ry);
void draw_ellipse(Point center, int rx, int ry);
void draw_ellipse_filled(Point left_top, Point right_bottom);
void draw_ellipse_filled(int x, int y, int rx, int ry);
void draw_ellipse_filled(Point center, int rx, int ry);

void draw_ellipse_3D(Point left_top, Point right_bottom);
void draw_ellipse_3D(int x, int y, int rx, int ry);
void draw_ellipse_3D(Point center, int rx, int ry);
void draw_ellipse_3D_filled(Point left_top, Point right_bottom);
void draw_ellipse_3D_filled(int x, int y, int rx, int ry);
void draw_ellipse_3D_filled(Point center, int rx, int ry);

void draw_ellipse_P3D(Point left_top, Point right_bottom);
void draw_ellipse_P3D(int x, int y, int rx, int ry);
void draw_ellipse_P3D(Point center, int rx, int ry);
void draw_ellipse_P3D_filled(Point left_top, Point right_bottom);
void draw_ellipse_P3D_filled(int x, int y, int rx, int ry);
void draw_ellipse_P3D_filled(Point center, int rx, int ry);


The above overloads draw ellipses.

void draw_elliptic_arc(Point left_top, Point right_bottom, Point start_point, Point stop_point);
void draw_elliptic_arc(int x, int y, int rx, int ry, Point start_point, Point stop_point);
void draw_elliptic_arc(Point center, int rx, int ry, Point start_point, Point stop_point);

void draw_elliptic_arc(Point left_top, Point right_bottom, int start_angle, int end_angle);
void draw_elliptic_arc(int x, int y, int rx, int ry, int start_angle, int end_angle);
void draw_elliptic_arc(Point center, int rx, int ry, int start_angle, int end_angle);

void draw_elliptic_arc_filled(Point left_top, Point right_bottom, Point start_point, Point stop_point);
void draw_elliptic_arc_filled(int x, int y, int rx, int ry, Point start_point, Point stop_point);
void draw_elliptic_arc_filled(Point center, int rx, int ry, Point start_point, Point stop_point);

void draw_elliptic_arc_filled(Point left_top, Point right_bottom, int start_angle, int end_angle);
void draw_elliptic_arc_filled(int x, int y, int rx, int ry, int start_angle, int end_angle);
void draw_elliptic_arc_filled(Point center, int rx, int ry, int start_angle, int end_angle);

void draw_elliptic_arc_3D(Point left_top, Point right_bottom, Point start_point, Point stop_point);
void draw_elliptic_arc_3D(int x, int y, int rx, int ry, Point start_point, Point stop_point);
void draw_elliptic_arc_3D(Point center, int rx, int ry, Point start_point, Point stop_point);

void draw_elliptic_arc_3D(Point left_top, Point right_bottom, int start_angle, int end_angle);
void draw_elliptic_arc_3D(int x, int y, int rx, int ry, int start_angle, int end_angle);
void draw_elliptic_arc_3D(Point center, int rx, int ry, int start_angle, int end_angle);

void draw_elliptic_arc_3D_filled(Point left_top, Point right_bottom, Point start_point, Point stop_point);
void draw_elliptic_arc_3D_filled(int x, int y, int rx, int ry, Point start_point, Point stop_point);
void draw_elliptic_arc_3D_filled(Point center, int rx, int ry, Point start_point, Point stop_point);

void draw_elliptic_arc_3D_filled(Point left_top, Point right_bottom, int start_angle, int end_angle);
void draw_elliptic_arc_3D_filled(int x, int y, int rx, int ry, int start_angle, int end_angle);
void draw_elliptic_arc_3D_filled(Point center, int rx, int ry, int start_angle, int end_angle);

void draw_elliptic_arc_P3D(Point left_top, Point right_bottom, Point start_point, Point stop_point);
void draw_elliptic_arc_P3D(int x, int y, int rx, int ry, Point start_point, Point stop_point);
void draw_elliptic_arc_P3D(Point center, int rx, int ry, Point start_point, Point stop_point);

void draw_elliptic_arc_P3D(Point left_top, Point right_bottom, int start_angle, int end_angle);
void draw_elliptic_arc_P3D(int x, int y, int rx, int ry, int start_angle, int end_angle);
void draw_elliptic_arc_P3D(Point center, int rx, int ry, int start_angle, int end_angle);

void draw_elliptic_arc_P3D_filled(Point left_top, Point right_bottom, Point start_point, Point stop_point);
void draw_elliptic_arc_P3D_filled(int x, int y, int rx, int ry, Point start_point, Point stop_point);
void draw_elliptic_arc_P3D_filled(Point center, int rx, int ry, Point start_point, Point stop_point);

void draw_elliptic_arc_P3D_filled(Point left_top, Point right_bottom, int start_angle, int end_angle);
void draw_elliptic_arc_P3D_filled(int x, int y, int rx, int ry, int start_angle, int end_angle);
void draw_elliptic_arc_P3D_filled(Point center, int rx, int ry, int start_angle, int end_angle);


The above overloads draw elliptic_arcs.

void draw_elliptic_ngon(int x, int y, int rx, int ry, int n, int rot = 0);
void draw_elliptic_ngon(Point center, int rx, int ry, int n, int rot = 0);
void draw_elliptic_ngon(Point left_top, Point right_bottom, int n, int rot = 0);
void draw_elliptic_ngon_filled(int x, int y, int rx, int ry, int n, int rot = 0);
void draw_elliptic_ngon_filled(Point center, int rx, int ry, int n, int rot = 0);
void draw_elliptic_ngon_filled(Point left_top, Point right_bottom, int n, int rot = 0);

void draw_elliptic_ngon_3D(int x, int y, int rx, int ry, int n, int rot = 0);
void draw_elliptic_ngon_3D(Point center, int rx, int ry, int n, int rot = 0);
void draw_elliptic_ngon_3D(Point left_top, Point right_bottom, int n, int rot = 0);
void draw_elliptic_ngon_3D_filled(int x, int y, int rx, int ry, int n, int rot = 0);
void draw_elliptic_ngon_3D_filled(Point center, int rx, int ry, int n, int rot = 0);
void draw_elliptic_ngon_3D_filled(Point left_top, Point right_bottom, int n, int rot = 0);

void draw_elliptic_ngon_P3D(int x, int y, int rx, int ry, int n, int rot = 0); 
void draw_elliptic_ngon_P3D(Point center, int rx, int ry, int n, int rot = 0);
void draw_elliptic_ngon_P3D(Point left_top, Point right_bottom, int n, int rot = 0); 
void draw_elliptic_ngon_P3D_filled(int x, int y, int rx, int ry, int n, int rot = 0);
void draw_elliptic_ngon_P3D_filled(Point center, int rx, int ry, int n, int rot = 0);
void draw_elliptic_ngon_P3D_filled(Point left_top, Point right_bottom, int n, int rot = 0);

The above overloads draw elliptic_ngons which are polygons inscribed in an ellipse.  The angle rot in degrees rotates the ellipse. See also elliptic_outgons for polygons circumscribed about an ellipse.

void draw_elliptic_outgon(int x, int y, int rx, int ry, int n, int rot = 0);
void draw_elliptic_outgon(Point center, int rx, int ry, int n, int rot = 0);
void draw_elliptic_outgon(Point left_top, Point right_bottom, int n, int rot = 0);
void draw_elliptic_outgon_filled(int x, int y, int rx, int ry, int n, int rot = 0);
void draw_elliptic_outgon_filled(Point center, int rx, int ry, int n, int rot = 0);
void draw_elliptic_outgon_filled(Point left_top, Point right_bottom, int n, int rot = 0);

void draw_elliptic_outgon_3D(int x, int y, int rx, int ry, int n, int rot = 0);
void draw_elliptic_outgon_3D(Point center, int rx, int ry, int n, int rot = 0);
void draw_elliptic_outgon_3D(Point left_top, Point right_bottom, int n, int rot = 0);
void draw_elliptic_outgon_3D_filled(int x, int y, int rx, int ry, int n, int rot = 0);
void draw_elliptic_outgon_3D_filled(Point center, int rx, int ry, int n, int rot = 0);
void draw_elliptic_outgon_3D_filled(Point left_top, Point right_bottom, int n, int rot = 0);

void draw_elliptic_outgon_P3D(int x, int y, int rx, int ry, int n, int rot = 0); 
void draw_elliptic_outgon_P3D(Point center, int rx, int ry, int n, int rot = 0);
void draw_elliptic_outgon_P3D(Point left_top, Point right_bottom, int n, int rot = 0);
void draw_elliptic_outgon_P3D_filled(int x, int y, int rx, int ry, int n, int rot = 0);
void draw_elliptic_outgon_P3D_filled(Point center, int rx, int ry, int n, int rot = 0);
void draw_elliptic_outgon_P3D_filled(Point left_top, Point right_bottom, int n, int rot = 0);


The above overloads draw elliptic_outgons which are polygons circumscribed about an ellipse.  The angle rot in degrees rotates the ellipse. See also elliptic_ngons for polygons inscribed in an ellipse.

std::string draw_input_text(int x, int y, std::string prompt = "");
std::string draw_input_text(Point p, std::string prompt = "");
std::string draw_input_text_3D(int x, int y, std::string prompt = "");
std::string draw_input_text_3D(Point p, std::string prompt = "");
std::string draw_input_text_P3D(int x, int y, std::string prompt = "");
std::string draw_input_text_P3D(Point p, std::string prompt = "");

These functions post an optional prompt and wait for the user to input something followed by pressing the "enter" key.  The entered string is returned.  See to_int() and to_double() for converting string values to numerical values.  If these functions are used on a portion of the screen whose color is different than the background color, try setting the background color to the color over which the functions are acting.

void draw_line(int x1, int y1, int x2, int y2);
void draw_line(Point p, int x2, int y2);
void draw_line(int x1, int y1, Point q);
void draw_line(Point p, Point q);

void draw_line_3D(int x1, int y1, int x2, int y2);
void draw_line_3D(Point p, int x2, int y2);
void draw_line_3D(int x1, int y1, Point q);
void draw_line_3D(Point p, Point q);

void draw_line_P3D(int x1, int y1, int x2, int y2);
void draw_line_P3D(Point p, int x2, int y2);
void draw_line_P3D(int x1, int y1, Point q);
void draw_line_P3D(Point p, Point q);


These functions draw lines.  Note that there is no "filled" modifier for lines.

void draw_ngon(int x, int y, int r, int n, int rot = 0);
void draw_ngon(Point center, int r, int n, int rot = 0);
void draw_ngon_filled(int x, int y, int r, int n, int rot = 0);
void draw_ngon_filled(Point center, int r, int n, int rot = 0);

void draw_ngon_3D(int x, int y, int r, int n, int rot = 0);
void draw_ngon_3D(Point center, int r, int n, int rot = 0);
void draw_ngon_3D_filled(int x, int y, int r, int n, int rot = 0);
void draw_ngon_3D_filled(Point center, int r, int n, int rot = 0);

void draw_ngon_P3D(int x, int y, int r, int n, int rot = 0);
void draw_ngon_P3D(Point center, int r, int n, int rot = 0);
void draw_ngon_P3D_filled(int x, int y, int r, int n, int rot = 0);
void draw_ngon_P3D_filled(Point center, int r, int n, int rot = 0);


These function draw regular n-sided polygons inscribed in a circle of radius r.  The default orientation has a bottom edge horizontal, but this can be changed with the optional rotation parameter.  See outgons for regular polygons circumscribed about a circle.

void draw_outgon(int x, int y, int r, int n, int rot = 0);
void draw_outgon(Point center, int r, int n, int rot = 0);
void draw_outgon_filled(int x, int y, int r, int n, int rot = 0);
void draw_outgon_filled(Point center, int r, int n, int rot = 0);

void draw_outgon_3D(int x, int y, int r, int n, int rot = 0);
void draw_outgon_3D(Point center, int r, int n, int rot = 0);
void draw_outgon_3D_filled(int x, int y, int r, int n, int rot = 0);
void draw_outgon_3D_filled(Point center, int r, int n, int rot = 0);

void draw_outgon_P3D(int x, int y, int r, int n, int rot = 0);
void draw_outgon_P3D(Point center, int r, int n, int rot = 0);
void draw_outgon_P3D_filled(int x, int y, int r, int n, int rot = 0);
void draw_outgon_P3D_filled(Point center, int r, int n, int rot = 0);


These function draw regular n-sided polygons circumscribed about a circle of radius r.  The default orientation has a bottom edge horizontal, but this can be changed with the optional rotation parameter.  See ngons for regular polygons inscribed in a circle.

void draw_point(int x, int y);
void draw_point(Point center);

void draw_point_3D(int x, int y);
void draw_point_3D(Point center);

void draw_point_P3D(int x, int y);
void draw_point_P3D(Point center);


These function draw a point.

void draw_polygon_f(Point* vertex_array, int ns);
void draw_polygon_f(int* coord_array, int ns);
void draw_polygon_filled_f(Point* vertex_array, int ns);
void draw_polygon_filled_f(int* coord_array, int ns);
void draw_polygon_3D_f(Point* vertex_array, int ns);
void draw_polygon_3D_f(int* coord_array, int ns);
void draw_polygon_3D_filled_f(Point* vertex_array, int ns);
void draw_polygon_3D_filled_f(int* coord_array, int ns);
void draw_polygon_P3D_f(Point* vertex_array, int ns);
void draw_polygon_P3D_f(int* coord_array, int ns);
void draw_polygon_P3D_filled_f(Point* vertex_array, int ns);
void draw_polygon_P3D_filled_f(int* coord_array, int ns);


These function connect the vertices and add a final line from the last vertex to the first.  The edges might possibly cross each other.  Note that these functions, with the _f at the end of the name, only need to be called in the case that the array is dynamically created with the new operator.  For ordinary arrays, omit the _f and also the size parameter.  For example, the following two drawing calls draw the same triangle.

int v[] = {10, 10, 100, 100, MidX, MidY};
Point w[] = {Point(10, 10), Point(100, 100), MidPt};
draw_polygon(v);
draw_polygon(w);

void draw_polyline_f(Point* vertex_array, int num_points);
void draw_polyline_f(int* coord_array, int num_points);
void draw_polyline_3D_f(Point* vertex_array, int num_points);
void draw_polyline_3D_f(int* coord_array, int num_points);
void draw_polyline_P3D_f(Point* vertex_array, int num_points);
void draw_polyline_P3D_f(int* coord_array, int num_points);


These function connect the vertices.  Note that these functions, with the _f at the end of the name, only need to be called in the case that the array is dynamically created with the new operator.  For ordinary arrays, omit the _f and also the size parameter.  For example, the following two drawing calls draw the 3 edged non-closed figure..

int v[] = {10, 10, 100, 100, MidX, MidY};
Point w[] = {Point(10, 10), Point(100, 100), MidPt};
draw_polyline(v);
draw_polyline(w);

void draw_rectangle(Point left_top, Point right_bottom, int rot = 0);
void draw_rectangle(int x, int y, int rx, int ry, int rot = 0);
void draw_rectangle(Point center, int rx, int ry, int rot = 0);

void draw_rectangle_filled(Point left_top, Point right_bottom, int rot = 0);
void draw_rectangle_filled(int x, int y, int rx, int ry, int rot = 0);
void draw_rectangle_filled(Point center, int rx, int ry, int rot = 0);

void draw_rectangle_3D(Point left_top, Point right_bottom, int rot = 0);
void draw_rectangle_3D(int x, int y, int rx, int ry, int rot = 0);
void draw_rectangle_3D(Point center, int rx, int ry, int rot = 0);

void draw_rectangle_3D_filled(Point left_top, Point right_bottom, int rot = 0);
void draw_rectangle_3D_filled(int x, int y, int rx, int ry, int rot = 0);
void draw_rectangle_3D_filled(Point center, int rx, int ry, int rot = 0);

void draw_rectangle_P3D(Point left_top, Point right_bottom, int rot = 0);
void draw_rectangle_P3D(int x, int y, int rx, int ry, int rot = 0);
void draw_rectangle_P3D(Point center, int rx, int ry, int rot = 0);

void draw_rectangle_P3D_filled(Point left_top, Point right_bottom, int rot = 0);
void draw_rectangle_P3D_filled(int x, int y, int rx, int ry, int rot = 0);
void draw_rectangle_P3D_filled(Point center, int rx, int ry, int rot = 0);


These function draw rectangles.  The last rotation parameter is optional.

void draw_square(int x, int y, int r, int rot = 0);
void draw_square(Point center, int r, int rot = 0);
void draw_square_filled(int x, int y, int r, int rot = 0);
void draw_square_filled(Point center, int r, int rot = 0);

void draw_square_3D(int x, int y, int r, int rot = 0);
void draw_square_3D(Point center, int r, int rot = 0);
void draw_square_3D_filled(int x, int y, int r, int rot = 0);
void draw_square_3D_filled(Point center, int r, int rot = 0);

void draw_square_P3D(int x, int y, int r, int rot = 0);
void draw_square_P3D(Point center, int r, int rot = 0);
void draw_square_P3D_filled(int x, int y, int r, int rot = 0);
void draw_square_P3D_filled(Point center, int r, int rot = 0);


These function draw rectangles.  The last rotation parameter is optional.

void draw_text(int x, int y, std::string message);
void draw_text(Point p, std::string message);
void draw_text(int x, int y, char ch);
void draw_text(Point p, char ch);
void draw_text_3D(int x, int y, std::string message);
void draw_text_3D(Point p, std::string message);
void draw_text_3D(int x, int y, char ch);
void draw_text_3D(Point p, char ch);
void draw_text_P3D(int x, int y, std::string message);
void draw_text_P3D(Point p, std::string message);
void draw_text_P3D(int x, int y, char ch);
void draw_text_P3D(Point p, char ch);

These functions draw text to the screen.  They are overloaded to handle strings or characters.  To draw numbers to the screen, use the to_string() functions.

Point ellipse_point(Point left_top, Point right_bottom, int angle, int rot = 0);
Point ellipse_point(int x, int y, int rx, int ry, int angle, int rot = 0);
Point ellipse_point(Point center, int rx, int ry, int angle, int rot = 0);
Point ellipse_point(Point left_top, Point right_bottom, Point ray_point, int rot = 0);
Point ellipse_point(int x, int y, int rx, int ry, Point ray_point, int rot = 0);
Point ellipse_point(Point center, int rx, int ry, Point ray_point, int rot = 0);


Returns the point on an (optionally rotated) ellipse at a given angle or in a given direction.  For example, the following draws a point on an ellipse centered in the screen with a radius of 100 horizontally and 200 vertically that is 45 degrees counter-clockwise from "east".

draw_point( circle_point(MidPt, 100, 200, 45 ) );

The following draws a point on the same elllipse, rotated 30 degrees, that is in the direction of a ray from the center of the ellipse to the lower-right corner of the screen.

draw_point( circle_point(MidPt, 100, 200, MaxPt, 30) );

void erase();
void erase(Color color);
void erase(int r, int g, int b);
void erase(int x, int y, int rx, int ry);
void erase(Point center, int rx, int ry);
void erase(Point left_top, Point right_bottom);

We erase the currently active page, either entirely or in part.  Note that the background color is changed in the two cases where a new color is specified.

void erase_buffer();
void erase_buffer(Color color);
void erase_buffer(int r, int g, int b);
void erase_buffer(int x, int y, int rx, int ry);
void erase_buffer(Point center, int rx, int ry);
void erase_buffer(Point left_top, Point right_bottom
);

We erase the buffer, either entirely or in part.  Note that the background color is changed in the two cases where a new color is specified.

void erase_buffer2();
void erase_buffer2(Color color);
void erase_buffer2(int r, int g, int b);
void erase_buffer2(int x, int y, int rx, int ry);
void erase_buffer2(Point center, int rx, int ry);
void erase_buffer2(Point left_top, Point right_bottom);

We erase the secondary buffer, either entirely or in part.  Note that the background color is changed in the two cases where a new color is specified.

void flood_fill(int x, int y);
void flood_fill(Point fillPt);
void flood_fill(int x, int y, Color border_color);
void flood_fill(Point fillPt, Color border_color);
void flood_fill(int x, int y, int r, int g, int b);
void flood_fill(Point fillPt, int r, int g, int b);

The flood_fill command allows you to fill a region with the current fill color starting from a point and extending in every direction until reaching the current pen color.  Imagine a bucket of paint being poured from a point and flooding outward until stopped by a boundary in every direction.  Instead of the pen color, another color can be specified instead, either as a named color or as an RGB triple.

The flood_fill command can be dangerous.  If there is a "leak" in the boundary, the entire screen might be filled.  The danger of this can be lessened by drawing the outline with a pen of width greater than 1.  Another pitfall is filling a region such as a circle from its center point and then animating the circle so that it moves off the screen.  Once the center of the circle is off the screen, the portion of the circle that is on the screen no longer is filled.  In general, flood_fills in animations should be avoided because the flood_filling process is particularly slow and its implementation speed tends to vary greater between different computers of the same processing speed.

bool is_char();
bool is_click();


These functions return a true if the user has pressed a key or clicked the mouse.  They do not halt the program execution, but rather return their value immediately.  You can imagine that there are two buffers, one to store the character of the last key pressed and one to store the point at which the mouse was last clicked.  Each of these buffers can hold a single item or no item.  The is_char() and is_click() functions tell whether the buffers are empty and do not remove any items from the buffer for which you need remove_char() / remove_click() or get_char() / get_click().

A convenient use of these functions is to control the execution of a loop until the user responds such as with a while(!is_click()){...

int get_3D_angle_x();
int get_3D_angle_y();

These functions return the angle in degrees which determines the direction in which draw_<some_shape>_3D functions extend into the third dimension.  For the x-coordinate angles range from -45 degrees to the left through 0 degrees straight back into the screen to 45 degrees to the right.  For the y-coordinate angles range from -45 degrees upward through 0 degrees straight back into the screen to 45 degrees downward.  Angles outside of this range are possible but do not necessarily correspond to a physical angle.

Color get_3D_color();

This function returns the color of the part of 3D and P3D drawings that extend into the screen.

int get_3D_depth();

This functions returns the depth to which 3D and P3D drawings extend into the screen.  Note that P3D figures drawn close to the vanishing point cannot extend past the vanishing point even if the 3D_depth value is sufficient.

int get_3D_flare();

This function returns the flare which affects the way that 3D (but not P3D) drawings extend into the screen.  With a default value of 0, 3D modified draw extend straight back.  Negative values cause the extension to become smaller with depth until at -45 degrees of flare the extension culminates in a single point.  Imagine a circle extending back into the screen.  With a flare of 0 it would look like a cylinder while a flare of -45 would give a cone.  Positive angle flare outward.  At 45 degrees the original shape or text might look twice as wide at the back end than it is at the front.  Angles outside of the range from -45 to 45 are possible and can give interesting effects which may or may not correspond to "reality".

int get_3D_spacing();

This function returns the spacing or gap between the successive layers of 3D and P3D modified draws.  A spacing of one gives a solid appearance while spacings greater than one give an increasingly wire-frame or spring-like look to the object.

int get_3D_twist();

This function returns the twist of 3D and P3D modified draws.  As an object is extended into the screen it can be twisted or rotated by an angle.  For a circle we would not notice the twist, but for a square we would.  Angles are measured with positive being counter-clockwise and larger angles giving more of a twisting effect, something like one degree per pixel per 45 degrees twist.

Point get_3D_vanishing_point();

This function returns the vanishing point used by the P3D-modified drawing functions.

int get_active_page();

This function returns the currently active page, that is the page affected by draws and erases.  Page 0 is the visible screen, page 1 is the animation buffer, and page 2 is the secondary buffer.  These values are assigned to the constants SCREEN, BUFFER, and BUFFER2 respectively, so you could test if(get_active_page() == SCREEN) for example.

int get_animation_easing();

This function returns the easing which affects how animations proceed in time.  With an easing of 0 animations proceed at a constant rate.  For every 10 units of easing the last frame of the animation should take 100% more time to complete than the first frame did.  Thus with an easing of 10 the first frame should be twice as fast as the last and with an easing of 100 the first frame should be 11 times as fast as the last frame.  Negative easing work the to speed things up with every -10 units of easing causing the last frame of the animation to be 100% faster than the first frame.

bool get_animation_erase();

This function returns true or false depending on the animation erase mode.  By default, the screen is erased between every frame, but when animation_erase is false, this erasure does not occur, causing moving objects to leave a trial or "onion-skin" as they move.

int get_animation_frames_per_second();

This function returns the number of frames per second that the computer will attempt to render in animations.  Animations will slow down to match the current f.p.s., but if the processor cannot keep up with too high of a setting then the animation may not finish in its allotted time.

bool get_animation_repeat();

This function returns a true or false depending on whether the animation is currently in repeat/loop or will only play once.

Color get_background_color();

This function returns the current background_color which is used by the erasing functions.

char get_char(bool wait = true, bool remove_prior = false, bool remove_returned = true);
Point get_click(bool wait = true, bool remove_prior = false, bool remove_returned = true);

Imagine that there are two buffers which store the last key pressed and the point at which the mouse was last clicked.  Each of these buffers can hold a single item or no item.  At any time we could look at these buffers.  The wait parameter would determine whether we should wait until something is on a buffer if we find nothing there when we look, halting the entire program in that case, or whether we should return immediately with an answer.  The remove_prior parameter determines whether we should remove anything we find on a buffer and only consider buffer items after that removal.  The remove_returned parameter determines whether we should clear the buffer after we return from the function call.

With that said, we almost always call these functions with no parameters, giving them their default values.  For example, calling get_char() without parameters will return the last character that the user pressed and will halt the program until a keypress is made if the user has not pressed a key.  To only consider keypresses from a certain time forward and not accidental earlier keypresses, call remove_char() (or remove_click()) immediately before the get function.  See also is_char() and is_click().

Unlike other get functions for which there is a corresponding set function, there is no corresponding set function in this case.

Color get_color(int x, int y);
Color get_color(Point p);

This function returns the color of a point on the active page, usually the visible screen.  Note that this function differs from the other get function which have a corresponding set function.  The set_color() function does that set the color of a pixel, but rather changes the current major colors: fill_color, pen_color, pixel_color, and text_color.

Color get_fill_color();

This function returns the current fill color that will be used by the draw_<shape>_filled functions for shading interiors.

Color get_pen_color();

This function returns the current pen color that is used by drawing functions to determine the outlines of shapes.

int get_pen_style();

This function returns a value equal to one of the constants SOLID_PEN, DOT_PEN, DASH_PEN, DASH_DOT_PEN, or DASH_DOT_DOT_PEN.  This property affects the appearance of the outline of shapes when the pen_width is 1.  With a pen width of 1, the default SOLID_PEN is used.

int get_pen_width();

This function returns the pixel width used by the pen to draw the outline of shapes.  If the width is greater than one, then the SOLID_PEN pen_style will be used.

Color get_pixel_color();

This function returns the value of the current pixel_color used by draw_point.  Note that set_pixel_color, set_pen_color, and set_color all can change the pixel_color.

int get_text_alignment();

This function returns a value equal to one of the constants CENTER, LEFT_TOP, CENTER_TOP, RIGHT_TOP, LEFT_BASELINE, CENTER_BASELINE, RIGHT_BASELINE, LEFT_BOTTOM, CENTER_BOTTOM, or RIGHT_BOTTOM.  This affects how the draw_text(x, y, ...) functions position text relative to the (x,y).

Color get_text_color();

This function returns the current text_color used by the draw_text functions.  Note that set_text_color and set_color both affect this color.

std::string get_text_font();

This function returns the name of the current text_font.  For convenience, the following constant assignments have been made for fonts that are guaranteed to be on any Windows computer: COURIER "Courier New", TIMES "Times New Roman", ARIAL "Arial", COURIER_BOLD "Courier New Bold", TIMES_BOLD "Times New Roman Bold", ARIAL_BOLD "Arial Bold", COURIER_ITALIC "Courier New Italic", TIMES_ITALIC "Times New Roman Italic", ARIAL_ITALIC "Arial Italic", COURIER_BOLD_ITALIC "Courier New Bold Italic", TIMES_BOLD_ITALIC "Times New Roman Bold Italic", ARIAL_BOLD_ITALIC "Arial Bold Italic", SYMBOL "Symbol".

int get_text_rotation();

This function returns the angle in degrees with which the draw_text functions rotate text around the point specified by text_alignment.  Zero degrees is to the right and positive angles increase counter-clockwise.

int get_text_size();

This function returns that point size used by draw_text to render text in the current font.  The typical size of text found in printed books is 12 points.  See also the related functions text_height() and text_width() which return values in pixels.

#define InCurrentAnimation (Animator::current -> proportion())

This is used as the default value for the proportion parameter in the range functions.  It returns a number from 0 through 1 indicating how far along the current animation is.

int message_box(std::string message, std::string caption, int buttons = DEFAULT_MB,  int icon = DEFAULT_MB, int default_button = DEFAULT_MB);
int message_box(std::string message, int buttons = DEFAULT_MB, int default_button = DEFAULT_MB, int icon = DEFAULT_MB);

This function causes a message box to appear displaying some message to the user and waiting for the user to dismiss the message box before allowing the program to proceed.  By default the message box will have an OK button which must be clicked to dismiss the box.

After the message parameter, there is an optional caption parameter which will place that caption on the title bar of the message box.

Whether or not a caption parameter is given, the programmer has the option of giving from 0-3 additional parameters to affect the buttons and icons of the message box.  The order of these parameters is arbitrary, but up to one of the following constants can be passed from each category:

Category 1 - buttons appearing

BUTTONS_ABORT_RETRY_IGNORE, BUTTON_OK, BUTTONS_OK_CANCEL, BUTTONS_RETRY_CANCEL, BUTTONS_YES_NO, BUTTONS_YES_NO_CANCEL

Category 2: icons appearing

ICON_EXCLAMATION for warnings, ICON_INFORMATION for a lower case 'i' in a circle, ICON_QUESTION for a question mark, or ICON_STOP for a hand

Category 3 - default button if user presses "enter" instead of clicking the mouse:

DEFAULT_BUTTON1, DEFAULT_BUTTON2, DEFAULT_BUTTON3, DEFAULT_BUTTON4

For example, to display the message "Do you want to proceed?" with 'yes' and 'no' buttons and a question mark icon, use

message_box("Do you want to proceed?", "", BUTTONS_YES_NO, ICON_QUESTION);

The return value of the function will be equal to one of the following integer constants depending on the button that the user selected to dismiss the message box: BUTTON_ABORT, BUTTON_CANCEL, BUTTON_IGNORE, BUTTON_NO, BUTTON_OK, BUTTON_RETRY, or BUTTON_YES.  If a message box has a Cancel button, the function returns the BUTTON_CANCEL value if either the 'esc' key is pressed or the Cancel button is selected. If the message box has no Cancel button, pressing 'esc' has no effect.

void open_window(int width = -1, int height = -1, std::string caption = "GrafiX");
void open_window(std::string caption);

These functions are called by the GrafiX environment when grafix.cpp is compiled.  An instance of the Init class is created and its constructor calls open_window.  In general the user should not call the open_window function.

const double pi = 3.14159265358979323846;

bool point_in_rectangle(Point left_top, Point right_bottom, Point p);
bool point_in_rectangle(int x, int y, int rx, int ry, Point p);
bool point_in_rectangle(Point center, int rx, int ry, Point p);

These functions return true whenever the given point is in the specified rectangular region.

void play_sound(std::string sound_file, bool loop = false);

Calling play_sound with a .wav sound file causes the sound to be sent to the speakers.  The program can continue execution.  There is no internal way to determine if the sound is finished.  If this is important, load the sound into a sound playing program to determine its length, and then call the delay() function for this interval of time or use the time() function to time its completion.

If the file name is given, then that file must be in the same folder as the executable at the time the program is run.  A typical program is moving an executable without moving its sound files with it.  Alternatively, the file name can be given as a complete path as in "c:/windows/desktop/filename.wav".  The last parameter is optional and determines whether the sound should repeat upon completion.  Playing another sound while one is currently playing stops the first sound.  See also stop_sound().

class Point
{
public:
   Point();
   Point(int x, int y);

   bool operator==(Point rhs);
   bool operator!=(Point rhs);

   Point operator+(Point rhs);
   Point operator-(Point rhs);

   int x, y;
};

The plus and minus operators work by adding or subtracting coordinates, so MidPt + Point(1,0) is one pixel to the right of the middle of the screen.  For details about the Point class, click here.

Point  and coordinate macros

#define MaxX (screen_width() - 1)
#define MaxY (screen_height() - 1)
#define MaxPt Point(MaxX, MaxY)


These give information about the largest screen coordinate at the bottom right.

#define MidX (screen_width() / 2)
#define MidY (screen_height() / 2)
#define MidPt Point(MidX,MidY)


These give information about the middle of the screen.

#define MinX 0
#define MinY 0
#define MinPt Point(0,0)


These give information about the smallest screen coordinate, the orgin.

#define PerX(percent) percent * MaxX / 100
#define PerY(percent) percent * MaxY / 100
#define PerPt(percent1, percent2) Point(PerX(percent1), PerY(percent2))

These give information about places on the screen at certain percent values of the full screen, allowing for graphical programming that is independent of the screen size.  For example, to draw a circle in the middle of the upper-right quadrant, which is 75% of the way across the screen and 25% of the way down, we could use

draw_circle( PerPt(75, 25), MaxY / 4);
#define RanX random_x()
#define RanY random_y()
#define RanPt random_point()

These give random points or coordinates on the screen.

#define CurX cursor_x()
#define CurY cursor_y()
#define CurPt cursor_point()

These give information about the current location of the cursor.  See also cursor_x_rescaled() and cursor_y_rescaled().

#define VanPt get_3D_vanishing_point()

This gives the vanishing point used by P3D-modified functions.

#define LMinPt MinPt
#define LMidPt PerPt(0,50)
#define LMaxPt PerPt(0,100)
#define RMinPt PerPt(100,0)
#define RMidPt PerPt(100,50)
#define RMaxPt MaxPt
#define TMinPt MinPt
#define TMidPt PerPt(50,0)
#define TMaxPt PerPt(100,0)
#define BMinPt PerPt(0,100)
#define BMidPt PerPt(50,100)
#define BMaxPt MaxPt

Using L, R, T, B for left, right, top, and bottom, we define combinations to specify all corner points of the 4 screen quadrants.

#define LTMidPt PerPt(25,25)
#define RTMidPt PerPt(75,25)
#define LBMidPt PerPt(25,75)
#define RBMidPt PerPt(75,75)

Using L, R, T, B for left, right, top, and bottom, we define combinations to specify all midpoints of the 4 screen quadrants.

#define CLTPt(row, col, r, c) PerPt(100.0 * (col - 1) / c , 100.0 * (row - 1.0) / r)
#define CRTPt(row, col, r, c) PerPt(100.0 * col / c, 100.0 * (row - 1) / r)
#define CLBPt(row, col, r, c) PerPt(100.0 * (col - 1) / c, 100.0 * row / r)
#define CRBPt(row, col, r, c) PerPt(100.0 * col / c, 100.0 * row / r)

Think of C as denoting the row x col cell in an r x c screen grid.  Then, for example, CLTPt(row, col, r, c) is the left-top point of the cell at row x col in a full-screen grid that is r x c.  (All indices begin from 1.)

#define CMidPt(row, col, r, c) PerPt((100 * col - 50.0) / c, (100 * row - 50.0) / r)

Think of C as denoting the row x col cell in an r x c screen grid.  For example, if we carve the screen into 8 rows by 10 columns, the midpoint of the upper left cell would be CMidPt(1,1,8,10).  (All indices begin from 1.)

void quit(bool close_window_immediately = true);
void quit_confirm(bool close_window_immediately = true);

This quit function causes the program to terminate immediately.  If the parameter is true or omitted, the GrafiX window is also closed.  A parameter set to false as in quit(false) leaves the window open until the user presses a key or clicks the mouse.  Typically when the main() function ends, the GrafiX window remains until the user dismisses it, so the quit() function as the last line of main() is useful for closing the window immediately.

The quit_confirm() function behaves much like the quit() function except that a message box  appears asking for confirmation before quitting.

int random(int high);
int random(int low, int high);

These functions return a random integer either in the range from 1 through high or from low through high depending on whether 1 or 2 parameters are given.

Color random_blue (int low = 0, int high = 255);

This function returns a color with only blue intensity.  If no parameters are given, then the intensity is from 0 through 255.  If only 1 parameter is given, it is the low and a random intensity from low through 255 is returned.  With 2 parameters, a random color with blue intensity between the parameters is returned.

Color random_color();
Color random_color(Color low, Color high);

A random color is returned, or one within the sub-cube bounded by two given colors in the RGB parameter space cube.  Typically, we just use random_color() without any arguments.  See also random_blue(), random_green(), and random_red().

double random_continuous(double low, double high, double increment = .01);

A random number is returned between the low and high.  By default, the legal values between the endpoints come in .01 increments.  For example, if the low is 0 and the high is 1, then one of 0.00, 0.01, 0.02, ..., 0.99, 1.00.  If finer increments are wanted, the optional third parameter can be set.  If an increment is too large, the function may over-ride the user's choice.

Color random_green(int low = 0, int high = 255);

This function returns a color with only green intensity.  If no parameters are given, then the intensity is from 0 through 255.  If only 1 parameter is given, it is the low and a random intensity from low through 255 is returned.  With 2 parameters, a random color with green intensity between the parameters is returned.

Point random_point();
Point random_point(int x, int y, int rx, int ry);
Point random_point(Point center, int rx, int ry);
Point random_point(Point left_top, Point right_bottom);
Point random_point(int inset_x, int inset_y);

These functions generate a random point either within the whole screen, within a rectangular region specified in one of four ways:

  1. with center (x,y) and radii rx and ry horizontally and vertically.
  2. with center given by a Point named center, with rx and ry also given.
  3. with left_top and bottom_right Points given.
  4. with an inset border, given in pixels, horizontally and vertically from the screen's edge.

Color random_red (int low = 0, int high = 255);

This function returns a color with only red intensity.  If no parameters are given, then the intensity is from 0 through 255.  If only 1 parameter is given, it is the low and a random intensity from low through 255 is returned.  With 2 parameters, a random color with red intensity between the parameters is returned.

int random_x();
int random_y();

These functions generate a random integer from 0 through the maximum screen coordinate.

Color range(Color start, Color end, double proportion = InCurrentAnimation);
int range(int start, int end, double proportion = InCurrentAnimation);
Point range(Point start, Point end, double proportion = InCurrentAnimation);


The range functions return a value of the appropriate type between the start and end values.  If the third parameter is omitted, then we should be within an animation and the value returned is to the start as the animation's current clock is to its starting time.  For example, the following will draw a circle whose radius increases from 50 through 100 over 4 seconds.

ANIMATION(4, false)
{
   draw_circle(MidPt, range(50,100));
}

If the third parameter is specified as a number between 0 and 1, range will return the appropriate value which is that proportion of the way from the start value to the end value.

template <typename T>
T range(T* array, int size, double proportion = InCurrentAnimation);

Given an array of integers, colors, points, or any other type for which a basic range function is defined, we can range over the array.  The value of the range will start as the first array value, end as the last array value, and take on the intermediate values in between.  In the following example involving a 3 second animation, a circle will range from a radius of 50 initially, grow to 150 after 1 second, shrink to 75 at 2 seconds, and finish at 250.  The '3' in the range call is the size of the array.

int radii[] = {50, 150, 75, 250};
ANIMATE(3, false)
{
   draw_circle(MidPt, range(radii, 4));
}

This array form of the range function also accepts an optional proportion parameter that behaves like the proportion parameter of the basic range function.

double range_continuous(double start, double end, double proportion = InCurrentAnimation);

This function returns a value from start to end just like the basic range function, but the return value is continuous rather than limited to integers.

template <typename T>
T range_cycle(T start, T extreme, int num_cycles = 1, double proportion = InCurrentAnimation)

The range_cycle function allows us to cycle from a starting value to an extreme value and back to the starting value, and then to specify the number of cycles we will perform.  In the following example, the circle grows from a radius of 50 to 100 and back to 50 three times in the course of the six second animation.

ANIMATE(6, false)
{
   draw_circle(MidPt, range_cycle(50, 100, 3));
}

If the number-of-cycles parameter is omitted, then the default is 1 cycle.  An optional last parameter allows the range_cycle to return a value based on a proportion instead of an animation, just like with ranges.  Note that if the proportion parameter is included, the number-of-cycles parameters must also be included, even if it is 1.

This function will work for colors, integers, points, or any other type for which the basic range function is defined.

template <typename T>
T range_delay(T start, T end, int start_percent, int stop_percent, double proportion = InCurrentAnimation);

template <typename T>
T range_delay(T before, T start, T end, T after, int start_percent, int stop_percent, double proportion = InCurrentAnimation);

The range_delay function has two forms, both of which work on colors, integers, points, or any other type for which the basic range is defined.  In the first form we pass a starting and ending value (integer, color, or point), then we pass a starting and ending percent as integers from 0 through 100.  The idea is that the range_delay will assume its starting value until the starting percent of time has passed, then it will change steadily to its ending value until the ending percent of time has passed, and then it remains at that ending value until the animation ends.  For example, in the following 8 second animation, the circle will have a radius of 50 for the first 2 second, then grow to a radius of 100 over the next 4 seconds, and finally keep that radius of 100 for the last two seconds.  The 25 and 75 refer to 25% and 75% of the way through the animation.

ANIMATE(8, false)
{
   draw_circle(MidPt, range_delay(50, 100, 25, 75));
}

In the second form we pass a before-value, start-value, end-value, and after-value, followed by  the starting and stopping percentages.  The following circle has radii of 0 as its before and after values, and hence will not be seen.  The effect is that the circle suddenly appears after 2 seconds and disappears after 6 seconds.

ANIMATE(8, false)
{
   draw_circle(MidPt, range_delay(50, 100, 25, 75));
}


Using tricks like setting sizes to zero, points off the screen, or colors to be the same as the background color, we can make object appear and disappear with the second version of range_delay.  Note that both versions of range_delay also take an optional proportion parameter from 0 through 1 which allows them to be independent of an animation loop.

void remove_char();
void remove_click();

Imagine that there are two buffers for holding the character of the last key pressed and the point at which the user last clicked the mouse.  These buffers can each hold one single item or may be empty.  Calling the remove functions empties the buffers.  This is useful before a call to get_char() or get_click() if you want to be sure that you are responding to a user response after a certain time rather than an accidental response from a previous time.

void rotate(Point* point_array, int num_points, int x, int y, int angle);
void rotate(Point* point_array, int num_points, Point center, int angle);
Point rotate(Point p, int x, int y, int angle);
Point rotate(Point p, Point center, int angle);

These functions can take a point and return a new point which is the passed point rotated about a center by a certain angle, or they can take an entire array of points and rotate each point in the array.  Note that the array versions change the array whereas the individual point version leave the point unchanged and return a point.

int run_ time();

This function returns the time in milliseconds since the program began.  By calling the function and storing the value, we can determine an elapsed time.  For example, if I have a 31 second sound file and wish to have something occur while it plays, use

int begin = run_time();
while(run_time() - begin < 31000)
{
   //do whatever
}

void set_3D_angle_x(int t);
void set_3D_angle_y(int t);

These functions allow you to change the angle in degrees which determines the direction in which draw_<some_shape>_3D functions extend into the third dimension.  For the x-coordinate angles range from -45 degrees to the left through 0 degrees straight back into the screen to 45 degrees to the right.  For the y-coordinate angles range from -45 degrees upward through 0 degrees straight back into the screen to 45 degrees downward.  Angles outside of this range are possible but do not necessarily correspond to a physical angle.

void set_3D_color(Color c);
void set_3D_color(int r, int g, int b);

These functions set the color of the part of 3D and P3D drawings that extend into the screen.

void set_3D_depth (int n);

This functions sets the depth to which 3D and P3D drawings extend into the screen.  Note that P3D figures drawn close to the vanishing point cannot extend past the vanishing point even if the 3D_depth value is sufficient.

void set_3D_flare(int n);

This function sets the flare which affects the way that 3D (but not P3D) drawings extend into the screen.  With a default value of 0, 3D modified draw extend straight back.  Negative values cause the extension to become smaller with depth until at -45 degrees of flare the extension culminates in a single point.  Imagine a circle extending back into the screen.  With a flare of 0 it would look like a cylinder while a flare of -45 would give a cone.  Positive angle flare outward.  At 45 degrees the original shape or text might look twice as wide at the back end than it is at the front.  Angles outside of the range from -45 to 45 are possible and can give interesting effects which may or may not correspond to "reality".

void set_3D_spacing(int n);

This function sets the spacing or gap between the successive layers of 3D and P3D modified draws.  A spacing of one gives a solid appearance while spacings greater than one give an increasingly wire-frame or spring-like look to the object.

void set_3D_twist(int twist);

This function sets the twist of 3D and P3D modified draws.  As an object is extended into the screen it can be twisted or rotated by an angle.  For a circle we would not notice the twist, but for a square we would.  Angles are measured with positive being counter-clockwise and larger angles giving more of a twisting effect, something like one degree per pixel per 45 degrees twist.

void set_3D_vanishing_point (Point p);

This function retsetsurns the vanishing point used by the P3D-modified drawing functions.

void set_active_page(int page);

This function sets the currently active page, that is the page affected by draws and erases.  Page 0 is the visible screen, page 1 is the animation buffer, and page 2 is the secondary buffer.  These values are assigned to the constants SCREEN, BUFFER, and BUFFER2 respectively, so you could call set_active_page(SCREEN).

void set_animation_easing(int easing);

This function sets the easing which affects how animations proceed in time.  With an easing of 0 animations proceed at a constant rate.  For every 10 units of easing the last frame of the animation should take 100% more time to complete than the first frame did.  Thus with an easing of 10 the first frame should be twice as fast as the last and with an easing of 100 the first frame should be 11 times as fast as the last frame.  Negative easing work the to speed things up with every -10 units of easing causing the last frame of the animation to be 100% faster than the first frame.

void set_animation_erase(bool status);

This function sets the erase animation mode to true or false.  By default, the screen is erased between every frame, but when animation_erase is false, this erasure does not occur, causing moving objects to leave a trial or "onion-skin" as they move.

void set_animation_frames_per_second(int frames_per_second);

This function sets the number of frames per second that the computer will attempt to render in animations.  Animations will slow down to match the current f.p.s., but if the processor cannot keep up with too high of a setting then the animation may not finish in its allotted time.

void set_animation_repeat(bool repeat_status);

This function can be used to set the animation repeat mode to true or false depending on whether the animation should repeat/loop or only play once.

void set_background_color(Color color);
void set_background_color(int r, int g, int b);

This function sets the current background_color which is used by the erasing functions.

void set_color(Color color);
void set_color(int r, int g, int b);

These functions set the pen color used to draw shape outline, the fill color used to shade interiors of shapes, the text color, and the pixel color used by draw_point().  If speed is an issue and only certain colors need to be changed, a significant savings can be had by calling a subset of set_pen_color(),  set_fill_color(), set_text_color(), and set_pixel() color.

void set_fill_color(Color);
void set_fill_color(int, int, int);

This function sets the current fill color that will be used by the draw_<shape>_filled functions for shading interiors.

void set_pen_color(Color pen_color);
void set_pen_color(int r, int g, int b);

This function sets the current pen color that is used by drawing functions to determine the outlines of shapes.  It also sets the pixel color used by draw_point().  If only the pixel color needs to be changed, call set_pixel_color().

void set_pen_style(int pen_style_enum);

This function sets the pen_style to one of the constants SOLID_PEN, DOT_PEN, DASH_PEN, DASH_DOT_PEN, or DASH_DOT_DOT_PEN.  For example, set_pen_style(DOT_PEN) results in dotted borders for subsequently drawn shapes.  This property affects the appearance of the outline of shapes when the pen_width is 1.  With a pen width of 1, the default SOLID_PEN is used.

void set_pen_width(int pen_point_size);

This function sets the pixel width used by the pen to draw the outline of shapes.  If the width is greater than one, then the SOLID_PEN pen_style will be used.

void set_pixel_color(Color color);
void set_pixel_color(int r, int g, int b);

This function sets the value of the current pixel_color used by draw_point.  Note that set_pixel_color, set_pen_color, and set_color all can change the pixel_color.  If only the pixel_color needs to be changed, it is much more efficient to change only the pixel color than to change other colors at the same time.

void set_text_alignment(int align_enum);

This function sets the text_alignment to one of the constants CENTER, LEFT_TOP, CENTER_TOP, RIGHT_TOP, LEFT_BASELINE, CENTER_BASELINE, RIGHT_BASELINE, LEFT_BOTTOM, CENTER_BOTTOM, or RIGHT_BOTTOM.  This affects how the draw_text(x, y, ...) functions position text relative to the (x,y).


void set_text_color(Color color);
void set_text_color(int r, int g, int b);

This function returns the current text_color used by the draw_text functions.  Note that set_text_color and set_color both affect this color.  If only the text_color needs to be changed, then it is more efficient to use set_text_color() than set_color().

void set_text_font(std::string font_name = ""); //Default gives system font

This function sets text_font used by draw_text.  For convenience, the following constant assignments have been made for fonts that are guaranteed to be on any Windows computer: COURIER "Courier New", TIMES "Times New Roman", ARIAL "Arial", COURIER_BOLD "Courier New Bold", TIMES_BOLD "Times New Roman Bold", ARIAL_BOLD "Arial Bold", COURIER_ITALIC "Courier New Italic", TIMES_ITALIC "Times New Roman Italic", ARIAL_ITALIC "Arial Italic", COURIER_BOLD_ITALIC "Courier New Bold Italic", TIMES_BOLD_ITALIC "Times New Roman Bold Italic", ARIAL_BOLD_ITALIC "Arial Bold Italic", SYMBOL "Symbol".  For example, to set a Times New Roman font you could use either set_text_font(TIMES) or set_text_font("Times New Roman").

Other fonts on your system may be used, but if they are not available on the system that runs the program, a default system font will be used instead.  For example, we might try set_text_font("Garamond").

void set_text_rotation(int angle);

This function sets the angle in degrees with which the draw_text functions rotate text around the point specified by text_alignment.  Zero degrees is to the right and positive angles increase counter-clockwise.


void set_text_size(int points);

This function sets that point size used by draw_text to render text in the current font.  The typical size of text found in printed books is 12 points.  See also the related functions text_height() and text_width() which return values in pixels.

int screen_height();
int screen_width();

These functions return the height and width of the screen in pixels.  Note that the first coordinates of the screen start with x = 0 and y = 0, so MaxX equals screen_width() - 1.

void settings_3D_reset();
void settings_3D_restore();
void settings_3D_save();

These functions either reset the 3D properties to their default, restore from a previous save (or to the default if there has been no save), or save the current settings by taking a "snapshot" that can be restored later.

void settings_animation_reset();
void settings_animation_restore();
void settings_animation_save();

These functions either reset the animation properties to their default, restore from a previous save (or to the default if there has been no save), or save the current settings by taking a "snapshot" that can be restored later.

void settings_fill_reset();
void settings_fill_restore();
void settings_fill_save();

These functions either reset the fill properties to their default, restore from a previous save (or to the default if there has been no save), or save the current settings by taking a "snapshot" that can be restored later.

void settings_pen_reset();
void settings_pen_restore();
void settings_pen_save();

These functions either reset the pen properties to their default, restore from a previous save (or to the default if there has been no save), or save the current settings by taking a "snapshot" that can be restored later.

void settings_reset();
void settings_restore();
void settings_save();

These functions either reset the all the 3D, animation, fill, pen, and text properties to their default, restore from a previous save (or to the default if there has been no save), or save the current settings by taking a "snapshot" that can be restored later.

void settings_text_reset();
void settings_text_restore();
void settings_text_save();

These functions either reset the text properties to their default, restore from a previous save (or to the default if there has been no save), or save the current settings by taking a "snapshot" that can be restored later.

void stop_sound();

This function stops any currently playing sound started with play_sound().

int text_height(std::string s);
int text_width(std::string s);

These functions return the size in pixels of a particular string as it would be rendered in the current text_font and text_size.

double to_double(std::string);
int to_int(std::string);
int to_int(char);
std::string to_string(const char* str);
std::string to_string(char ch);
std::string to_string(int n);
std::string to_string(unsigned int n);
std::string to_string(double n);

These functions take a value from one data type and return the value converted to another data type.  This could be useful, for example, in drawing a numerical value to the screen with draw_text() which accepts strings.

void vertices_elliptic_ngon(Point* vertex_array, int x, int y, int rx, int ry, int ns, int rot = 0);
void vertices_elliptic_ngon(Point* vertex_array, Point center, int rx, int ry, int ns, int rot = 0);
void vertices_elliptic_outgon(Point* vertex_array, int x, int y, int rx, int ry, int ns, int rot = 0);
void vertices_elliptic_outgon(Point* vertex_array, Point center, int rx, int ry, int ns, int rot = 0);
void vertices_ngon(Point* vertex_array, int x, int y, int r, int ns, int rot = 0);
void vertices_ngon(Point* vertex_array, Point center, int r, int ns, int rot = 0);
void vertices_outgon(Point* vertex_array, int x, int y, int r, int ns, int rot = 0);
void vertices_outgon(Point* vertex_array, Point center, int r, int ns, int rot = 0);


These functions accept a (usually empty) array of the appropriate size and return the coordinates of the vertices of the shape.  Make sure that the array is at least as big as the number of sides of the shape.  For example, to draw small (radius 5) circles at the points of a hexagon, we could do the following.

Point v[6];
vertices_ngon(v, MidPt, 100, 6);
for(int i = 0; i < 6; i++)
   draw_circle( v[i], 5 );

The following would rotate those 6 points endlessly in a circle.

Point v[6];
ANIMATE(6, true)
{
   vertices_ngon(v, MidPt, 100, 6, range(0,360));
   for(int i = 0; i < 6; i++)
      draw_circle( v[i], 5 );
}

Home Introduction Installation Basic Lessons Just Enough C++ Advanced Lessons Reference Manual Packages Demos