Professional Documents
Culture Documents
programming in c
Nihar Ranjan Roy
Text Mode
80x25
640x480
void main()
{
int gd=DETECT,gm; //graphics driver & mode
initgraph(&gd,&gm,"c:\\tc\\bgi"); //initialise
circle(320,240,100); //draw circle(Cx,Cy,radius)
getch();
}
Graphics Driver?
*graphdriver is an integer that specifies the graphics driver to be
used. You can give it a value using a constant of the
graphics_drivers enumeration type, which is defined in
graphics.h and listed below.
graphics_drivers
Numeric value
constant
graphics_driver
s constant
Numeric value
DETECT
0 (requests
autodetect)
EGAMONO
IBM8514
CGA
HERCMONO
MCGA
ATT400
EGA
VGA
EGA64
PC3270
10
Graphics Mode
*graphmode is an integer that specifies the initial graphics mode
Driver
graphics_mode
Value
x Rows
CGA
CGAC0
320 x 200
C0
CGAC1
320 x 200
C1
CGAC2
320 x 200
C2
CGAC3
320 x 200
C3
CGAHI
640 x 200
2 color
Palette
Pages
Three Colors
LIGHTGREEN
LIGHTRED
YELLOW
LIGHTCYAN
LIGHTMAGENTA
WHITE
GREEN
RED
BROWN
CYAN
MAGENTA
LIGHTGRAY
Driver
graphics_mode
Value
x Rows
Palette
Pages
MCGAC0
320 x 200
C0
MCGAC1
320 x 200
C1
MCGAC2
320 x 200
C2
MCGAC3
320 x 200
C3
MCGAMED
640 x 200
2 color
MCGAHI
640 x 480
2 color
EGALO
640 x 200
16 color
EGAHI
640 x 350
16 color
EGA64LO
640 x 200
16 color
EGA64HI
640 x 350
4 color
EGA-MONO EGAMONOHI
640 x 350
2 color
1 w/64K
EGAMONOHI
640 x 350
2 color
2 w/256K
HERCMONOHI
720 x 348
2 color
MCGA
EGA
EGA64
HERC
Driver
ATT400
graphics_mode
Value
x Rows
Palette
Pages
ATT400C0
320 x 200
C0
ATT400C1
320 x 200
C1
ATT400C2
320 x 200
C2
ATT400C3
320 x 200
C3
ATT400MED
640 x 200
2 color
ATT400HI
640 x 400
2 color
VGALO
640 x 200
16 color
VGAMED
640 x 350
16 color
VGAHI
640 x 480
16 color
PC3270
PC3270HI
720 x 350
2 color
IBM8514
IBM8514HI
640 x 480
256 color
IBM8514LO
1024 x 768
256 color
VGA
Constant Name
Number
Meaning
grNotDetected
-2
grFileNotFound
-3
grInvalidDriver
-4
Invalid driver
grNoLoadMem
-5
Colors in VGA
Here are 16 colors declared in graphics.h as listed bellow.
BLACK
DARKGRAY:
BLUE:
LIGHTBLUE:
GREEN
LIGHTGREEN:
10
CYAN:
LIGHTCYAN:
11
RED
LIGHTRED:
12
MAGENTA:
LIGHTMAGENTA
13
BROWN:
YELLOW:
14
LIGHTGRAY
WHITE:
15
Fill Colors
void far setcolor(int color);
//setcolor sets the current drawing color to color, which
can range from 0 to getmaxcolor.
Value
EMPTY_FILL
Background color
SOLID_FILL
Solid fill
LINE_FILL
---
LTSLASH_FILL
///
SLASH_FILL
BKSLASH_FILL
LTBKSLASH_FILL
HATCH_FILL
Light hatch
XHATCH_FILL
Heavy crosshatch
INTERLEAVE_FILL
Interleaving lines
\\\
WIDE_DOT_FILL
10
CLOSE_DOT_FILL
11
USER_FILL
Nihar12
Ranjan Roy User-defined fill pattern
https://sites.google.com/site/niharran
Pixel
void far
//set the color of the pixel at location (x,y) with the specified color
LINES
line(x1,y1,x2,y2);
//draw a line from (x1,y1) and (x2,y2)
lineto(x2,y2);
//draw a line from current position to (X2,y2)
linerel(x1,y1,x2,y2);
Mouse Handling in C
The various mouse functions can be accessed by setting
up the AX register with different values (service number) and
issuing interrupt number 51. The functions are listed bellow
Interrupt
51
51
51
Service
0
Purpose
Reset mouse and get status
Call with AX = 0
Returns: AX = FFFFh If mouse support is available
Ax = 0 If mouse support is not available
51
51
51
51
Problem
Write a program in which the
mouse cursor is visible and its limit
is set to (x1,y1) to (x2,y2).
int callmouse()
{
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
union REGS in, out;
}
void restrictmouseptr(int x1,int y1,int x2,int y2)
{
in.x.ax=7; //set horizontal limit for mouse
in.x.cx=x1; //Min X
in.x.dx=x2; //Max X
int86(51,&in,&out);
in.x.ax=8; //set Vertical limit for the mouse
in.x.cx=y1; //min Y
in.x.dx=y2; //max Y
int86(51,&in,&out);
}
Nihar Ranjan Roy
https://sites.google.com/site/niharran
void main()
{
int x,y,cl,a,b;
int g=DETECT,m;
clrscr();
initgraph(&g,&m,"c:\\tc\\bgi");
rectangle(100,100,550,400);
callmouse();
restrictmouseptr(100,100,550,400);
getch();
}