Вы находитесь на странице: 1из 13

COMPUTER GRAPHICS

BY ANURAG
#include<stdio.h>

#include<conio.h>

#include<dos.h>

#include<stdlib.h>

#include<graphics.h>

void main()

int a=DETECT,b=DETECT;

initgraph(&a,&b,"");

setcolor(4);

line(10,10,300,300);

/* ARC,CIRCLE,PIE
*þ arc draws a circular arc

þ circle draws a circle

pieslice draws and fills a circular pie slice

Declaration:

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

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

þ void far pieslice(int x, int y, int stangle, int endangle, int radius);*/

arc(100,100,30,250,50);

circle(300,300,50);

pieslice(200,200,30,250,50);

/*BAR
Draws a bar

Declaration: void far bar(int left, int top, int right, int bottom); */

bar(50,70,70,300);

/*BAR3Dd
Draws a 3-D bar

Declaration: void far bar3d(int left, int top, int right, int bottom,

int depth, int topflag); */

bar3d(50,70,70,300,((50+70)/2),1);

/*CLEARSCREEN
Clears the graphics screen

Declaration: void far cleardevice(void);

CLEARVIEWPORT
Clears the current viewport

Declaration: void far clearviewport(void);

Remarks:

clearviewport erases the viewport and moves the CP (current position) to home (0,0), relative to the
viewport.

CLOSEGRAPH
Shuts down the graphics system

Declaration: void far closegraph(void);

Remarks:

closegraph deallocates all memory allocated by the graphics system.It then restores the screen to the
mode it was in before you called

initgraph.
DETECTGRAPH
Determines graphics driver and mode to use by checking the hardware.

Declaration:

void far detectgraph(int far *graphdriver, int far *graphmode);

Remarks:

detectgraph detects your system's graphics adapter and chooses the mode that

provides the highest resolution for that adapter.

DRAWPOLY,FILLPOLY
þ drawpoly draws the outline of a polygon

þ fillpoly draws and fills a polygon

Declaration:

þ void far drawpoly(int numpoints, int far *polypoints);

þ void far fillpoly(int numpoints, int far *polypoints);

Remarks:

drawpoly draws a polygon using the current line style and color.

fillpoly draws the outline of a polygon using the current line style and

color, then fills the polygon using the current fill pattern and fill color.

ELLIPSE,FILLELLIPSE,SECTOR
þ ellipse draws an elliptical arc

þ fillellipse draws and fills an ellipse

þ sector draws and fills an elliptical pie slice

Declaration:
þ void far ellipse(int x, int y, int stangle, int endangle,

int xradius, int yradius);

þ void far fillellipse(int x, int y,

int xradius, int yradius);

þ void far sector(int x, int y, int stangle, int endangle,

int xradius, int yradius);

Remarks:

ellipse draws an elliptical arc in the current drawing color.

fillellipse draws an ellipse, then fills the ellipse with the current fill

color and fill pattern.

sector draws and fills an elliptical pie slice in the current drawing color,

then fills it using the pattern and color defined by setfillstyle or

setfillpattern.

*/

ellipse(250,250,0,180,50,70);

fillellipse(500,350,70,50);

sector(200,400,0,180,50,70);

/*FLOODFILL
Flood-fills a bounded region

Declaration: void far floodfill(int x, int y, int border);

Remarks:

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.*/


//floodfill(300,300,50);

/* þ GETASPECTRATIO gets the current graphics mode's aspect ratio

þ SETASPECTRATIO sets the graphics aspect ratio

Declaration:

þ void far getaspectratio(int far *xasp, int far *yasp);

þ void far setaspectratio(int xasp, int yasp);

Remarks:

getaspectratio gets the aspect-ratio values in *xasp and *yasp.

setaspectratio changes the default aspect ratio of the graphics system.*/

setaspectratio(500,300);

/*

SETBACKGROUNDCOLOR,GETBACKGROUNDCOLOR
þ getbkcolor returns the current background color

þ setbkcolor sets the current background color using the palette

Declaration:

þ int far getbkcolor(void);

þ void far setbkcolor(int color);

Remarks:

getbkcolor returns the current background color.

setbkcolor sets the background to the color specified by color. */

setbkcolor(2);

/*GETCOLOR,SETCOLOR
þ getcolor returns the current drawing color

þ setcolor sets the current drawing color


Declaration:

þ int far getcolor(void);

þ void far setcolor(int color);

Remarks:

getcolor returns the current drawing color.

setcolor sets the current drawing color to color, which can range from 0 to

getmaxcolor.*/

setcolor(4);

/* þ GETFILLPATTERN copies a user-defined fill pattern into memory

þ SETFILLPATTERN selects a user-defined fill pattern

Declaration:

þ void far getfillpattern(char far *pattern);

þ void far setfillpattern(char far *upattern, int color);

Remarks:

getfillpattern copies the user-defined fill pattern (set by setfillpattern)

into the 8-byte area *pattern.

setfillpattern sets the current fill pattern to a user-defined 8x8 pattern.*/

/*GETIMAGE,PUTSETIMAGE
þ getimage saves a bit image of the specified region into memory

þ putimage outputs a bit image onto the screen

Declaration:

þ void far getimage(int left, int top, int right, int bottom,

void far *bitmap);

þ void far putimage(int left, int top, void far *bitmap, int op);
Remarks:

þ getimage copies an image from the screen to memory.

þ putimage puts the bit image previously saved with getimage back onto the

screen, with the upper left corner of the image placed at (left,top).

GETMAXX,GETMAXY
Returns maximum x or y screen coordinate

Declaration:

þ int far getmaxx(void);

þ int far getmaxy(void);

Remarks:

þ getmaxx returns the maximum x value (screen-relative) for the current

graphics driver and mode.

þ getmaxy returns the maximum y value (screen-relative) for the current

graphics driver and mode.

GETPIXEL,PUTPIXEL
þ getpixel gets the color of a specified pixel

þ putpixel plots a pixel at a specified point

Declaration:

þ unsigned far getpixel(int x, int y);

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

Remarks:

getpixel gets the color of the pixel located at (x,y).

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

*/
putpixel(500,700,4);

getpixel(500,700);

/* TEXTSETTINGS
Gets information about the current graphic text font

Declaration:

void far gettextsettings(struct textsettingstype far *texttypeinfo);

Remarks:

gettextsettings fills a structure with information about the current text

font, direction, size, and justification.

þ GETX returns the current position's x coordinate

þ GETYty returns the current position's y coordinate

Declaration:

þ int far getx(void);

þ int far gety(void);

Remarks:

þ getx returns the x-coordinate of the current graphics position.

þ gety returns the y-coordinate of the current graphics position.

INITGRAPH
Initializes the graphics system

Declaration:

void far initgraph(int far *graphdriver,

int far *graphmode, char far *pathtodriver);

Remarks:
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.

LINE,LINEREL,LINETO
þ line draws a line between two specified points

þ linerel draws a line a relative distance from the current position (CP)

þ lineto draws a line from the current position (CP) to (x,y)

Declaration:

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

þ void far linerel(int dx, int dy);

þ void far lineto(int x, int y);

Remarks:

þ line draws a line from (x1, y1) to (x2, y2) using the current color, line

style, and thickness. It does not update the current position (CP).

þ linerel draws a line from the CP to a point that is a relative distance

(dx, dy) from the CP, then advances the CP by (dx, dy).

þ lineto draws a line from the CP to (x, y), then moves the CP to (x, y).

*/

line(100,100,700,700);

linerel(50,90);

lineto(200,700);

/*MOVREL,MOVETO
þ moverel moves the current position (CP) a relative distance

þ moveto moves the CP to (x, y)


Declaration:

þ void far moverel(int dx, int dy);

þ void far moveto(int x, int y);

Remarks:

þ moverel moves the current position (CP) dx pixels in the x direction and

dy pixels in the y direction.

þ moveto moves the current position (CP) to viewport position (x, y).*/

moveto(0,0);

/*OUTTEXT,OUTTEXTXY
þ outtext displays a string in the viewport (graphics mode)

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

Declaration:

þ void far outtext(char far *textstring);

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

Remarks:

outtext and outtextxy display a text string, using the current justification

settings and the current font, direction, and size.

þ outtext outputs textstring at the current position (CP)

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

outtext("anurag kumar");

outtextxy(300,300,"Anurag Kumar");

/*RECTANGLE
Draws a rectangle (graphics mode)

Declaration:
void far rectangle(int left, int top, int right, int bottom);

Remarks:

rectangle draws a rectangle in the current line style, thickness, and

drawing color.*/

rectangle(200,200,300,400);

/*SETFILLSTYLE
Sets the fill pattern and color

Declaration: void far setfillstyle(int pattern, int color);

Remarks:

setfillstyle sets the current fill pattern and fill color.

SETLINESTYLE
Sets the current line style and width or pattern

Declaration:

void far setlinestyle(int linestyle, unsigned upattern, int thickness);

Remarks:

setlinestyle sets the style for all lines drawn by line, lineto, rectangle,

drawpoly, etc.

*/

setlinestyle(2,2,1000);

line(10,10,600,600);

/*SETTEXTJUSTIFY
Sets text justification for graphics mode

Declaration: void far settextjustify(int horiz, int vert);


Remarks:

Text output after a call to settextjustify is justified around the current

position (CP) horizontally and vertically, as specified.

SETTEXTSTYLE
Sets the current text characteristics

Declaration:

void far settextstyle(int font, int direction, int charsize);

Remarks:

settextstyle sets the text font, the direction in which text is displayed,

and the size of the characters.

SETUSERCHARSIZE
User-defined character magnification factor for stroked fonts

Declaration:

void far setusercharsize(int multx, int divx, int multy, int divy);

Remarks:

setusercharsize gives you finer control over the size of text from stroked

fonts used with graphics functions.*/

GLITTERING SKY

while(!kbhit())
{

delay(40);

putpixel(random(640),random(248),random(15));

getch();

Вам также может понравиться