|
|
|
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] WelcomeThe 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 commandsANIMATE(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(); 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); 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); 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. classColor { 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 }; booloperator==(Color& lhs, Color& rhs); bool operator!=(Color& lhs, Color& rhs); For details about the methods of the color class, click here.
template <typename S, typename T> 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(); 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); 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(); 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. 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); 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_filled(int x, int y, 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); 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); The above overloads draw circles. void draw_ellipse(Point left_top, Point right_bottom); void draw_elliptic_arc(Point left_top, Point right_bottom, Point
start_point, Point stop_point); void draw_elliptic_ngon(int x, int y, int rx, int ry, 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); std::string draw_input_text(int x, int y, 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_ngon(int x, int y, int r, int n, int rot = 0); void draw_outgon(int x, int y, int r, int n, int rot = 0); void draw_point(int x, int y); void draw_polygon_f(Point* vertex_array, int ns); 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); 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_square(int x, int y, int r, int rot = 0); void draw_text(int x, int y, std::string message); 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. 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(); 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(); 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(); 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. 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(); 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(); 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); 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); 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); 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:
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"); 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); These functions return true whenever the given point is in the specified rectangular region. void play_sound(std::string sound_file, bool loop = false); 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.
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. 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 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) Using L, R, T, B for left, right, top, and bottom, we define combinations
to specify all midpoints of the 4 screen quadrants. 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); 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); 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(); 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(); These functions generate a random point either within the whole screen, within a rectangular region specified in one of four ways:
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(); These functions generate a random integer from 0 through the maximum screen
coordinate. 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> 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); template <typename T> 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> template <typename T> 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));
}
void remove_char(); 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); 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. 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); 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); 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); This function sets the current background_color which is used by the erasing functions. void set_color(Color color); 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); 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); 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); 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).
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.
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. 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. 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(); 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. 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. 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. 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. 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. This function stops any currently playing sound started with play_sound(). 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); 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. 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 );
}
|