9
BGI graphics library And Visual Studio

BGI graphics library And Visual Studio. Layout of graphics window 0, 0 639, 479 X increasing YincreasingYincreasing

Embed Size (px)

Citation preview

Page 1: BGI graphics library And Visual Studio. Layout of graphics window 0, 0 639, 479 X  increasing YincreasingYincreasing

BGI graphics library

And Visual Studio

Page 2: BGI graphics library And Visual Studio. Layout of graphics window 0, 0 639, 479 X  increasing YincreasingYincreasing

Layout of graphics window

0, 0

639, 479

X increasing

Y

increasing

Page 3: BGI graphics library And Visual Studio. Layout of graphics window 0, 0 639, 479 X  increasing YincreasingYincreasing

Prolog required for every graphics program#include “graphics.h” - same place as other includesAND inside main() start graphics code with

initwindow (x, y); // x is the number of pixels horizontally// and y is the number of pixels vertically

orinitwindow (x, y, string); // where string is the title to go in

// the title bar of the graphics window

Page 4: BGI graphics library And Visual Studio. Layout of graphics window 0, 0 639, 479 X  increasing YincreasingYincreasing

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

Page 5: BGI graphics library And Visual Studio. Layout of graphics window 0, 0 639, 479 X  increasing YincreasingYincreasing

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

Page 6: BGI graphics library And Visual Studio. Layout of graphics window 0, 0 639, 479 X  increasing YincreasingYincreasing

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

Page 7: BGI graphics library And Visual Studio. Layout of graphics window 0, 0 639, 479 X  increasing YincreasingYincreasing

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

Page 8: BGI graphics library And Visual Studio. Layout of graphics window 0, 0 639, 479 X  increasing YincreasingYincreasing

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

Page 9: BGI graphics library And Visual Studio. Layout of graphics window 0, 0 639, 479 X  increasing YincreasingYincreasing

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