Sei sulla pagina 1di 36

arc function of c graphics

C program to draw Arc in C Graphics.

Syntax of arc in c graphics is arc(int x, int y, int starting-angle,int ending-angle, int radius);. Arc is used to draw circular arc. It takes 5 arguments, all of the int type. First two arguments define the center of the arc to place on the screen. hird and fourth arguments are starting and ending angles of the arc. Fifth argument is the radius of the arc in pixels.

C program to draw arc in c graphics


#include <graphics.h> #include <stdio.h>

int main( ) { int gd=DETECT, gm; initgraph( gd, gm,!C"##tc##$gi!); arc(%&',%&',(',)*',+'); getch(); closegraph(); return '; ,

!ar function of c graphics


C graphics program to draw !ar.

Syntax to draw a !ar is bar(int left,int top,int right,int bottom) "ar is used to draw rectangular !ar. It takes # arguments, all of the int datatypes. First two arguments are left$top corner of the !ar %ast two arguments are right$!ottom corner of the !ar.

C Graphics program to draw !ar.


#include <graphics.h> #include <stdio.h>

int main( ) { int gd=DETECT, gm; initgraph( gd, gm,!C"##tc##$gi!); $ar(%'',%'',-'',.''); getch();

closegraph(); return '; ,

!ar&d function of c graphics


C program to draw & dimensional !ar.

Syntax to draw & dimensional !ar is bar3d(int left.int top,int right,int bottom, int depth,int topflag) !ar&d is used to draw & dimensional rectangular !ar. It takes ' arguments, all of the int datatype. First two arguments are left$top corner of the !ar. hird and fourth arguments are right !ottom corner of the !ar. Fifth arguments is for specified depth of the !ar in pixels. Sixth argument is for determines whether a & dimensional top is put on the !ar or not.(if it is non )ero then it put other wise not.*

C graphics program to draw & dimensional !ar

#include <graphics.h> #include <stdio.h>

int main( ) { int gd=DETECT, gm; initgraph( gd, gm,!C"##tc##$gi!); $ar.d(%'',%'',-'',.'',-',('); getch(); closegraph(); return '; ,

Circle
C program to draw a circle in c graphics.

Syntax of drawing circle in c graphics is circle(int x, int y, int radius). he first two arguments are used to define center of the circle in x and y co$ordinates. hird argument of the circle is its radius in pixels.

C program to draw circle.


#include <graphics.h> #include <stdio.h>

int main( ) { int gd=DETECT, gm; initgraph( gd, gm,!C"##tc##$gi!); circle(%&',%&',('); getch(); closegraph(); return '; ,

c graphic program to draw polygon.


drawpoly function is used to draw polygon it may !e triangle, rectangle, hexagon, etc. In drawpoly function it will takes two argument first argument is num i.e num!er if points or +ertices and that is ( num , - *. And another is an array of points which gi+es the x and y coordinates of the point or +ertices of the polygon. In which array of polypoint is ( num . / * where num is num!er of points or +ertices. General syntax of polygon : drawpoly( int num, int polypoint); For example we need to draw rectangle using drawpoly function than the first argument num is num!er of +ertices , - that is 5 and the array of polypoints contain num . / elements so in rectangle num is 5 and polypoint are 5 . / 0 -1.

fillpoly is also used to draw and fill polygon. setfillstyle is used to apply different style to fill color and pattern in polygon.

! graphic program to demonstrate drawpoly function


#include <graphics.h> #include <stdio.h>

int main( ) { int gd=DETECT, gm; int points/0={%&',%.',.&',%.',.&',-'',)&',-'',%&',%.',; initgraph( gd, gm,!C"##tc##$gi!); dra1pol2(&,points); getch(); closegraph(); return '; ,

ellipse function of c graphics


C program to draw ellipse in c graphics

Syntax of ellipse is ellipse(int midx,int midy, int startingangle, int endingangle,int radiusx,int radiusy);

2llipse is used to draw an elliptical arc. 2llipse takes ' arguments, all of the int type. First two argument define the center of the ellipse to place on the screen. hird and fourth argument are starting and ending angles of the ellipse. Fifth argument is the radius of the ellipse in x axis and sixth argument is the radius of the ellipse in y axis.

C graphics program to draw ellipse.


#include <graphics.h> #include <stdio.h>

int main( ) { int gd=DETECT, gm; initgraph( gd, gm,!C"##tc##$gi!);

ellipse(%&',%&',',%+',3',%)'); getch(); closegraph(); return '; ,

fillpoly function c graphic


fillpoly function is used to draw and fill polygon. It will takes two argumnet same asdrawpoly function. General syntax of fillpoly function is : fillpoly( int num, int polypoint); fillpoly function fill white color !y default. o change fill color and pattern style we need to use setfillstyle function.

! graphic program to demonstrate fillpoly function.


#include <graphics.h> #include <stdio.h> int main( ) { int gd=DETECT, gm;

int points/0={%&',%.',.&',%.',.&',-'',)&',-'',%&',%.',; initgraph( gd, gm,!C"##tc##$gi!); 4illpol2(&,points); getch(); closegraph(); return '; ,

getmaxx function of c graphics


getmaxx function of c graphics programming is used tp get the maximum +alue of 3 coordinate on graphic screen usually it is '&4 for 5GA dri+er and 5GA6I graphics mode. getmaxy function is used to get the maximum +alue of 7 coordinate on graphic screen usually it is #84 for 5GA dri+er and 5GA6I graphic mode. General syntax of getmaxx function is: getmaxx(); hese function are +ery useful when we need to draw full screen rectanlge !order for our drawing. "or #xample: rectangle( $, $, getmaxx(), getmaxy() );

! graphics program to demonstrate getmaxx function.


#include <graphics.h> #include <stdio.h> int main( ) { int gd=DETECT, gm; char msg/&'0; initgraph( gd, gm,!C"##tc##$gi!); mo5eto().',)''); sprint4(msg,!6a7imum 5alue o4 8" 9d!,getma77()); outte7t(msg); getch(); closegraph(); return '; ,

getmaxcolor function of c graphics


getmaxcolor function of c graphics is used to get the maximum num!er of color in graphics mode. getcolor function is used to get the current foreground color in

graphic mode. General syntax of getmaxcolor function is : getmaxcolor();

C graphics program to demonstrate the getmaxcolor function.


#include <graphics.h> #include <stdio.h> int main( ) { int gd=DETECT, gm; char msg/&'0; initgraph( gd, gm,!C"##tc##$gi!); mo5eto().',)''); sprint4(msg,!6a7imum num$er o4 color" 9d!,getma7color()); outte7t(msg); getch(); closegraph(); return '; ,

getmaxy function of c graphics


getmaxy function of c graphics programming is used to get the maximum +alue of 7 coordinate on graphic screen usually it is #84 for 5GA dri+er and 5GA6I graphic mode.getmaxx function is used to get the maximum +alue of 3 coordinate on graphic screen usually it is '&4 for 5GA dri+er and 5GA6I graphics mode. General syntax of getmaxy function is: getmaxy(); hese function are +ery useful when we need to draw full screen rectanlge !order for our drawing. "or #xample: rectangle( $, $, getmaxx(), getmaxy() );

! graphics program to demonstrate getmaxy function.


#include <graphics.h> #include <stdio.h>

int main( ) { int gd=DETECT, gm; char msg/&'0; initgraph( gd, gm,!C"##tc##$gi!); mo5eto().',)''); sprint4(msg,!6a7imum 5alue o4 8" 9d!,getma72()); outte7t(msg); getch(); closegraph(); return '; ,

getmaxy function of c graphics


getmaxy function of c graphics programming is used to get the maximum +alue of 7 coordinate on graphic screen usually it is #84 for 5GA dri+er and 5GA6I graphic mode.getmaxx function is used to get the maximum +alue of 3 coordinate on graphic screen usually it is '&4 for 5GA dri+er and 5GA6I graphics mode. General syntax of getmaxy function is:

getmaxy(); hese function are +ery useful when we need to draw full screen rectanlge !order for our drawing. "or #xample: rectangle( $, $, getmaxx(), getmaxy() );

! graphics program to demonstrate getmaxy function.


#include <graphics.h> #include <stdio.h> int main( ) { int gd=DETECT, gm; char msg/&'0; initgraph( gd, gm,!C"##tc##$gi!); mo5eto().',)''); sprint4(msg,!6a7imum 5alue o4 8" 9d!,getma72()); outte7t(msg); getch(); closegraph(); return '; ,

gety function of c graphics


gety function is used to get the current position of y coordinate on screen. 9e can set the current position of cursor !y using mo%eto function. General syntax for gety function is: gety( );

! graphics program to demonstrate gety function.


#include <graphics.h> #include <stdio.h>

int main( ) { int gd=DETECT, gm; char msg/&'0; initgraph( gd, gm,!C"##tc##$gi!); mo5eto()'',%3'); sprint4(msg,!Current position o4 :" 9d!,get2()); outte7t(msg); getch();

closegraph(); return '; ,

line function of C graphic


! program to draw line in ! Graphics. %ine function is used to draw line from a point (x-,y-* to a point (x/,y/*.It takes # arguments. In which First two argument is the starting point of the line on x$axis and y$axis and %ast two argument is the ending point of the line on x axis and y$ axis. General syntax of line function is : line( int sx-pos, int sy-pos, int ex-pos, int ey-pos); "y default line function draw line as S:%I;<%I=2. o set different line style we need to use setlinestyle function of graphics.h !efore the line function.

C Graphics program to draw line

#include<graphics.h> #include<conio.h> main() { int gd = DETECT, gm; initgraph( gd, gm, !C"##TC##;<=!);

line(%'', %'', )'', )''); getch(); closegraph(); return '; ,

lineto function in graphics


lineto function is used to draw line from current position to the point(x,y*. lineto function takes two arguments, !oth are integer datatype. he !oth argument indicate the ending position of line on x and y coordinate. General syntax of lineto function is: lineto( int endx-pos, int endy-pos ); 9e can get current position !y

using getx andgety function. And we can set the current position of cursor !y using mo%eto function. And we can also set the line style !y using setlinestyle function. line function takes four argument to draw line. All are integer datatype. First two argument is for set the starting position of x and y coordinate of line and another two argument is for set the ending position of x and y coordinate of line. "ut in lineto function the starting position of line is current position of cursor.

! Graphics program to demonstrate the lineto function


#include <graphics.h> #include <stdio.h> int main( ) { int gd=DETECT, gm; initgraph( gd, gm,!C"##tc##$gi!); setlinest2le(),),.); mo5eto(%'',)''); lineto(-'',)''); getch(); closegraph(); return '; ,

mo+eto function in c graphic


mo+eto function is use to mo+e cursor position at particular position. It takes / arguments, !oth are int type. 9hich specify x and y coordinate on screen to put cursor. General syntax of mo%eto function is mo%eto( int x-pos, int y-pos );

>o+eto function is used with outtext function to display text or string at particular location on screen.

C Graphic program to demonstrate mo+eto function


#include <graphics.h> #include <stdio.h>

int main( ) { int gd=DETECT, gm; char msg/0=!Demonstration o4 mo5eto 4unction!; initgraph( gd, gm,!C"##tc##$gi!); set$>color(+); mo5eto()'',%-'); outte7t(!?rogrammingcampus.com!); mo5eto()'',%*'); outte7t(msg); getch(); closegraph(); return '; ,

mo+eref function in c graphics


mo+eref function of c graphics is used to mo+e the text from current position to rele+ent location. General syntax of mo%eref function is: mo%eref(int offset-x, int offset-y); It will take two arguments , !oth are integer datatypes. In which first argument is offset of x cordinate and second argument is offset of y cordinate.

"or example: Current position is (-11,/11* after use of mo+eref(/11,&11*, now current position of text is (&11,511*.

C graphics program to demonstrate the mo+eref function


#include <graphics.h> #include <conio.h> main() { int gd = DETECT, gm, 7, 2; char msg/%''0,msg%/%''0; initgraph( gd, gm, !C"##TC##;<=!); mo5eto(%'',%''); 7 = get7(); 2 = get2(); sprint4(msg,!Current 7 position = 9d and 2 position = 9d $e4ore mo5ere4!,7,2); outte7t72(%',)',msg); mo5erel(%'', )''); 7 = get7(); 2 = get2(); sprint4(msg%, !Current 7 position = 9d and 2 position = 9d a4ter mo5ere4!, 7, 2); outte7t72(%', &', msg%); getch(); closegraph(); return '; ,

pieslice function in c graphics


V7DEQYYCZD8R

pieslice function of c graphics is used to draw the circle and this circle is filled with color and?or style. In contrast of pieslice circle only draw the outline of the circle. General syntax of pieslice function in c graphics is: pieslice(int xpos, int ypos, int sangle, int eangle, int radius); pieslice function takes 5 argument, all are integer datatype. First two is the center point of pieslice on 3 and 7 coordinate respecti+ely. hird and fourth argument is starting and ending angle of pieslice function respecti+ely. And fifth argument is the radius of pieslice. pieslice is fill the color and style !y using setfillstyle function of c graphics.

C graphic program to demonstrate pieslice function of graphics.h


#include<graphics.h> #include<conio.h>

main() { int gd = DETECT, gm; initgraph( gd, gm, !C"##TC##;<=!); set4illst2le(),&); pieslice(.'',)&',',%3',%''); getch(); closegraph(); return '; ,

rectangle function of c graphics


! program to draw rectangle in c graphics.

Syntax of rectangle function is rectangle(left, top, right, bottom)@ Aectangle is used to draw empty rectangle. It takes # arguments all of int types. First two arguments are left$top corner of the rectangle and last two arguments are right$!ottom corner of the rectangle.

C program to draw rectangle


#include <graphics.h> #include <stdio.h>

int main( ) { int gd=DETECT, gm; initgraph( gd, gm,!C"##tc##$gi!); rectangle(%'',%'',-'',.''); getch(); closegraph(); return '; ,

sector function of c graphic


C graphics program to draw sector.

General syntax of sector is sector(int x,int y,int sangle,int eangle,int xradius,int yradius) Sector is used to draw and fills elliptical pie slice. It takes ' arguments, all int data tyape. he first two arguments are used to define center of the circle in x and y co$ordinates. hird and fourth arguments are starting and ending angles of the sector. Fifth argument is the radius of the ellipse in x axis and sixth argument is the radius of the ellipse in y axis.

C Brogram to draw sector

#include <graphics.h> #include <stdio.h>

int main( ) { int gd=DETECT, gm; initgraph( gd, gm,!C"##tc##$gi!); sector(%&', %&', %', %-&, (&, +&); getch(); closegraph(); return '; ,

set!kcolor function in graphics


C graphics program to set !ackground color.

General syntax to set !ackground color is setb&color(int color). !kcolor is used to set !ackground color of the screen. Its take only one argument it may !e a int or char data type.

In set!kcolor function we can choose color !y its int +alue(1$-5* or !y color name 'he following table shown color name and it corresponding int %alue . Color BLACK BLUE GREEN CYAN RED MAGENTA BROWN LIGHTGRAY DARKGRAY LIGHTBLUE LIGHTGREEN LIGHTCYAN LIGHTRED LIGHTMAGENTA YELLOW WHITE 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 int value

C program to set !ackground


#include <graphics.h> #include <stdio.h>

int main( ) { int gd=DETECT, gm; initgraph( gd, gm,!C"##tc##$gi!); set$>color(%); getch(); closegraph();

return '; ,

setfillstyle function in c graphic


setfillstyle function is used to set the current fill pattern and color. General syntax of setfillstyle function is : setfillstyle( int pattern, int color ); In setfillstyle we can choose any pattern and color !y its name as its corresponding intger +alues. 'here are following patterns in a%ailable with setfillstyle function with its corresponding integer %alue. Fill Style Name EMPTY_FILL OLID_FILL LINE_FILL LT LA H_FILL LA H_FILL BK LA H_FILL LTBK LA H_FILL HATCH_FILL 1 2 3 4 5 6 7 8 int value

!HATCH_FILL INTERLEA"E_FILL WIDE_DOT_FILL CLO E_DOT_FILL U ER_FILL

9 10 11 12 13

'here are following color is a%ailable with setfillstyle function with its corresponding integer %alue. Color BLACK BLUE GREEN CYAN RED MAGENTA BROWN LIGHTGRAY DARKGRAY LIGHTBLUE LIGHTGREEN LIGHTCYAN LIGHTRED LIGHTMAGENTA YELLOW WHITE 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 int value

! graphic program to demonstrate setfillstyle function


#include <graphics.h> #include <stdio.h> int main( )

{ int gd=DETECT, gm; int points/0={%'',%&',.'',%&',.'',-'',)&',-'',%'',%&',; initgraph( gd, gm,!C"##tc##$gi!); set4illst2le(3,%); 4illpol2(&,points); getch(); closegraph(); return '; ,

setlinestyle function of c graphic


! program to set the different line style

setlinestyle function is used to set the line style. General syntax of setlinestyle function is : setlinestyle( int linestyle, unsigned upattern, int thic&ness); It takes & argument first one is the line style. here are following line style a+aila!le with the setlinestyle function with its corresponding integer +alue. Line Style OLID_LINE DOTTED_LINE CENTER_LINE DA HED_LINE U ERBIT_LINE 0 1 2 3 4 int value

he second argument is to use !it pattern and last one is for lineCs thickness it can !e - pixel or & pixel wide.

! graphic program to demonstrate setlinestyle function


#include <graphics.h> #include <stdio.h>

int main( ) { int gd=DETECT, gm; initgraph( gd, gm,!C"##tc##$gi!); setlinest2le(%,%,%); line(%'',%'',-'',%''); setlinest2le(D@ABEDCD=EE,%,.); line(%'',%&',-'',%&'); setlinest2le(),%,%);

line(%'',)'',-'',)''); getch(); closegraph(); return '; ,

settextstyle function in c graphic


settextstyle function is used to set text style of gi+en string. It modify the font style, direction of string and font si)e. It is used with outtext or outtextxy function. settextstyle function takes & input arguments namely font$style, direction(hori)ontal or +ertical* and font si)e. General syntax of settextstyle function is : settextstyle(int fontstyle, int direction, int char-si(e);

In settextstyle function we can choose font style !y its int +alue or !y font style name. And direction of text !y int +alue( 1 or - * or !y direction name( 6:AID<;IA or 52A <;IA *. he following ta!le shown the font style name and its corresponding int +alue. Font Style Name DEFAULT_FONT TRIPLE!_FONT MALL_FONT AN _ ERIF_FONT GOTHIC_FONT CRIPT_FONT IMPLE!_FONT TRIPLE!_ CR_FONT COMPLE!_FONT EUROPEAN_FONT BOLD_FONT 0 1 2 3 4 5 6 7 8 9 10 int value

C graphic program to demonstrate outtextxy function.


#include <graphics.h> #include <stdio.h> int main( ) { int gd=DETECT, gm; char msg/0=!Demonstration o4 sette7tst2le 4unction!; initgraph( gd, gm,!C"##tc##$gi!); set$>color(+); sette7tst2le(%,',));

outte7t72()'',%.',!?rogrammingcampus.com!); sette7tst2le(A@EACAEF=GCGHET,BHF=ICD=F,.); outte7t72()'',%*',msg); getch(); closegraph(); return '; ,

outtext function in c graphic


outtext is the function used to display the gi+en string on graphics mode at current position . outtext function takes only one argument that is char .string type. o change the position of text or string we need to use mo%eto function. outtext function display string in its default text style. o change font style we need to use settextstyle function !efore the outtext function. General syntax of outtext function is : outtext( char string);

C graphics program to demonstrate outtext function.

#include <graphics.h> #include <stdio.h> int main( ) { int gd=DETECT, gm; char msg/0=!Demonstration o4 outte7t 4unction!; initgraph( gd, gm,!C"##tc##$gi!); set$>color(+); mo5eto()'',%-'); outte7t(!?rogrammingcampus.com!); mo5eto()'',%*'); outte7t(msg); getch(); closegraph(); return '; ,

outtextxy function in c graphic

outtextxy is the function used to display the gi+en string on graphics mode at specific position . outtextxy function takes & argument, first two as int type which specify the position of string on screen. And last argument is char type which is text or string which display on screen. outtextxy function use its default font style to display gi+en string . o change font style we need to use settextstyle function !efore the outtextxy function. outtextxy function is an alternati+e of outtext function which specify particular location of string or text on the screen. General syntax of outtextxy function is : outtextxy(int x-pos, int y-pos, char string);

C graphics program to demonstrate outtextxy function.


#include <graphics.h> #include <stdio.h>

int main( ) { int gd=DETECT, gm; char msg/0=!Demonstration o4 outte7t72 4unction!; initgraph( gd, gm,!C"##tc##$gi!); set$>color(+); outte7t72()'',%.',!?rogrammingcampus.com!); outte7t72()'',%*',msg); getch(); closegraph(); return '; ,

Potrebbero piacerti anche