Sei sulla pagina 1di 19

C++ AND GRAPHICS

Graphics tools
OpenGL
Qt
BGI (Borland Graphics Interface)
WinBGI (Windows Borland Graphics Interface)
WinBGI
Copy graphics.h to include file
Copy libbgi.a to lib file
In Project | Project Options | Parameters
add to Linker
-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32
Open Graphics window
#include <graphics.h>
int main(){
initwindow(400,300);
system (pause);
return 0;
}
Close Graphics window
#include <graphics.h>
int main(){
initwindow(400,300);
while(!kbhit()); //keyboard hit
closegraph();
//system (pause);
return 0;
}

Close Graphics window
#include <graphics.h>
int main(){
initwindow(400,300);
delay(4000); //delay in milliseconds
closegraph();
//system (pause);
return 0;
}

Coordinates
X=0
Y=100
Y=0
X=100
X=50 Y=100
X=150 Y=50
Move point
int main()
{
initwindow(400,300);

moveto(0,0);

while(!kbhit());
closegraph();
return 0;
}
Draw line from point
int main()
{
initwindow(400,300);

moveto(0,0);
lineto(150,150);

while(!kbhit());
closegraph();
return 0;
}

Draw a circle
int main()
{
initwindow(400,300);

//circle(x, y, radius);
circle(150,150,50);

while(!kbhit());
closegraph();
return 0;
}
Colors
Named Colors (0 to 15):
BLACK BLUE GREEN
CYAN RED MAGENTA
BROWN LIGHTGRAY DARKGRAY
LIGHTBLUE LIGHTGREEN LIGHTCYAN
LIGHTRED LIGHTMAGENTA YELLOW
WHITE

User Specified:
COLOR(255,100,0)
Color the lines
int main()
{
initwindow(400,300);

setcolor(YELLOW);
circle(150,150,50);

while(!kbhit());
closegraph();
return 0;
}
Color the surface
int main()
{
initwindow(400,300);

setfillstyle(1, 12);
bar(100, 100, 150, 250);

while(!kbhit());
closegraph();
return 0;
}
Styles
Surfaces 0 to 12
EMPTY_FILL SOLID_FILL
LINE_FILL LTSLASH_FILL
SLASH_FILL BKSLASH_FILL
LTBKSLASH_FILL HATCH_FILL
XHATCH_FILL INTERLEAVE_FILL
WIDE_DOT_FILL CLOSE_DOT_FILL
Example
int main()
{
initwindow(400,300);

setfillstyle(11, 10);
bar(100, 100, 250, 250);

while(!kbhit());
closegraph();
return 0;
}
int main()
{
initwindow(400,300);

setfillstyle(INTERLEAVE_FILL, YELLOW);
bar(100, 100, 250, 250);

while(!kbhit());
closegraph();
return 0;
}
Loop around
int main()
{
initwindow(400,300);
int xmax = 350;
int ymax = 250;
for (int n=0; n<5; n++){
setcolor(WHITE);
rectangle(100+(n-1)*50, 100+n*30, 100+n*50, ymax);
setfillstyle(n, n);
bar(101+(n-1)*50, 101+n*30, 100+n*50, ymax);
}

while(!kbhit());
closegraph();
return 0;
}
Adding Text
int main()
{
initwindow(400,300);
int xmax = 350;
int ymax = 250;
floodfill(2, 2, 6);
for (int n=0; n<6; n++){
setcolor(WHITE);
rectangle(100+(n-1)*50, 100+n*30, 100+n*50, ymax);
setfillstyle(n, n);
bar(101+(n-1)*50, 101+n*30, 100+n*50, ymax);
}
outtextxy(100, 270, "My Graph Sample");
while(!kbhit());
closegraph();
return 0;
}

Potrebbero piacerti anche