Presentation is loading. Please wait.

Presentation is loading. Please wait.

BGI graphics library And Visual Studio.

Similar presentations


Presentation on theme: "BGI graphics library And Visual Studio."— Presentation transcript:

1 BGI graphics library And Visual Studio

2 Layout of graphics window
X  increasing 0, 0 Y increasing 639, 479

3 Prolog required for every graphics program
#include “graphics.h” - same place as other includes AND inside main() start graphics code with initwindow (x, y); // x is the number of pixels horizontally // and y is the number of pixels vertically or initwindow (x, y, string); // where string is the title to go in // the title bar of the graphics window

4 Required at end of program
closegraph(); usually right before return 0; if you want to pause the graphics window you can use getch(); this is a function that will get a character from the keyboard and discard it

5 Functions x = getmaxx(); y = getmaxy();
return the highest x value and y value possible in the current graphics mode These can be useful if you want something centered in the window putpixel (x/2, y/2, RED); would put a tiny red dot in the middle of the window

6 To pause the program getch();
strictly this does return the character that was pressed on the keyboard, but for this use we do not care what character was pressed. So the function can be called as a “void” function, i.e. on a line by itself

7 More Functions - Color void setcolor (int color); color used to draw with void setfillpattern (SOLID_FILL, BLUE); will cause any 'filled' or 'bar' calls after that to fill in solidly with blue BLUE, GREEN, CYAN, RED and so on are named constants (actually integers) that you can use as color arguments; SOLID_FILL, LINE_FILL, SLASH_FILL are the same for fill patterns

8 More functions void line (int x1, int y1, int x2, int y2 ); draws a line from (x1, y1) to (x2, y2) line (25, 50, 35, 50); // horizontal void rectangle (int left, int top, int right, int bottom); rectangle (150, 200, 400, 350); // a box that is 250 pixels wide and 150 tall

9 Another function outtextxy(x, y, "This is a test.");
(x,y) is where the text will start on the screen if you want to pass a string variable to this function, you must use outtextxy (x, y, const_cast<char*>(str.c_str())); where str is the name of the string variable


Download ppt "BGI graphics library And Visual Studio."

Similar presentations


Ads by Google