You are on page 1of 5

PART-1

Basics/Inbuilt functions in computer graphics

Introduction & Theory


GRAPHICS.H

GRAPHICS.H is a header file in C that is used for drawing various shapes and other graphics. It is also
used to color the objects drawn. We can also find out the coordinates of points on the screen using it. In
order to be able to use graphics.h we need to have the drivers installed and recognized by the program.
Also the graphics card inserted in the computer needs to be known.

INITGRAPH
Initializes the graphics system

Void initgraph (int *graphdriver,int *graphmode, char *pathtodriver);

To start the graphics system, you must first call initgraph. Initgraph initializes the graphics system by
loading a graphics driver from disk (or validating a registered driver) then putting the system into
graphics mode. Initgraph also resets all graphics settings (color, palette, current position, viewport, etc.) to
their defaults, and then resets graph result to 0.

LINE
Line is an inbuilt function present in graphics.h that draws a line in the current drawing color between two
given coordinates.

void line(int x1,int y1,int x2,int y2);

Line draws a line from point (x1,y1) to point (x2,y2) using the current drawing color, line style and
thickness. It does not update the current position (CP).

In order to draw a line using this function, one just need to call the function line and pass the values of the
x and y coordinates of the initial and final points of the line.

CIRCLE
Circle is an inbuilt function present in graphics.h that draws a circle in the current drawing color.

void circle(int x, int y, int radius);

x and y are the coordinates of the center of the circle and radius is the value of radius of circle. In order to
draw a circle using this function, one just needs to call the function circle and pass the values of the center
of the circle and its radius.

RECTANGLE
Rectangle is an inbuilt function present in graphics.h that draws a rectangle in the current drawing color,
line style and thickness.

void rectangle(int left,int top,int right,int bottom);


(left, top) is the upper left corner of the rectangle and (right, bottom) is the bottom right corner. In order
to draw a rectangle using this function, one just need to call the function rectangle and pass the values of
the x and y coordinates of the top left and bottom right corners of the rectangle.

ARC
Arc is a built in function in C/C++ that is used to draw circular arcs. This function draws a circular arc in
the given drawing color.

void arc (int x, int y, int stangle, int endangle, int radius);

Here, x, y are the coordinates of the center of the arc, stangle is the starting angle of arc in degrees and
endangle is the ending angle of arc in degrees and radius id the radius of the arc. Arc travels from stangle
to endangle. If stangle is 0 degrees and endangle is 360 degrees, the arc drawn is a circle.

CLEARDEVICE
void cleardevice(void);

Cleardevice erases the entire graphics screen and moves the CP (current position) to home (0, 0).

GETMAXCOLOR
Getmaxcolor returns the highest valid color value that can be passed to setcolor for the current graphics
driver and mode

void getmaxcolor(void);

On a 256 EGA getmaxcolor will always return 15. This means that any color value in the range 0-15 is
valid and can be given to setcolor.

FLOODFILL
Floodfill is an inbuilt function in graphics.h that fills a bounded region. Floodfill fills an enclosed area on
bitmap devices. The area bounded by the color border is flooded with the current fill pattern and fill color.

void floodfill(int x, int y, int border);

where (x, y) is a "seed point". If the seed is within an enclosed area, the inside will be filled.If the seed is
outside the enclosed area, the exterior will be filled.

GETPIXEL
Getpixel gets the color of a specified pixel. Its declaration is given as:

unsigned getpixel(int x, int y);

Getpixel gets the color of the pixel located at (x, y) and returns its color value.

PUTPIXEL
Putpixel plots a pixel at a specified point. Its declaration is given as:

void putpixel(int x, int y, int color);


Putpixel plots a point in the color defined by color at (x, y).

GETCOLOR
getcolor returns the current drawing color.

int getcolor(void);

The drawing color is the value that pixels are set to when the program draws lines, etc.

SETCOLOR
setcolor sets the current drawing color

void setcolor(int color);

setcolor sets the current drawing color to color, which can range from 0 to getmaxcolor. To select a
drawing color with setcolor, you can pass either the color number or the equivalent color name.

GETMAXX AND GETMAXY


Returns maximum x or y screen coordinate. The declaration is given as:

int getmaxx(void);
int getmaxy(void);

getmaxx returns the maximum x value (screen-relative) for the current graphics driver and mode and
getmaxy returns the maximum y value (screen-relative) for the current graphics driver and mode. On a
CGA in 320 x 200 mode, getmaxx returns 319 and getmaxy returns 199.

OUTTEXTXY
outtextxy displays a string at the specified location (graphics mode).

void outtextxy(int x, int y, char far *textstring);

outtextxy displays textstring in the viewport at the position (x, y)

SETVIEWPORT
Sets the current viewport for graphics output.

void setviewport(int left, int top, int right, int bottom, int clip);

Setviewport establishes a new viewport for graphics output. The viewport's corners are given in absolute
screen coordinates by (left, top) and (right, bottom).The current position (CP) is moved to (0, 0) in the
new window. The clip argument determines whether drawings are clipped (truncated) at the current
viewport boundaries. If clip is non-zero, all drawings will be clipped to the current viewport.
NOTE:

Experiments of this part is from S. No. 1 to S. No. 6

Mandatory assignment for this part is given below

Q1.What is pixel.

Q2. What do you mean by resolution?

Q3.What is an image aspect ratio?

Q4. Explain frame buffer?

Q5.What is the function of the control electrode in a CRT?

Q6. Explain the terms interactive and non interactive computer graphics.

Q7. What are the three major adverse side effects of scan conversion?

You might also like