Basic Functions of c Graphics

download Basic Functions of c Graphics

of 36

Transcript of Basic Functions of c Graphics

  • 8/13/2019 Basic Functions of c Graphics

    1/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 #include

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

    arc(%&',%&',',*',+'); getch(); closegraph();

    return ';

  • 8/13/2019 Basic Functions of c Graphics

    2/36

    !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 #include

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

    $ar(%'',%'',-'',''); getch();

    http://4.bp.blogspot.com/-PrpDirrIOWw/UUiSE1yYmuI/AAAAAAAAAi4/82DzYSXbihI/s1600/arc.png
  • 8/13/2019 Basic Functions of c Graphics

    3/36

    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 #include

    http://2.bp.blogspot.com/-LHM0cSZ-CJ4/UUsjrx4l5qI/AAAAAAAAAjY/tBsRlNwlQVA/s1600/bar.png
  • 8/13/2019 Basic Functions of c Graphics

    4/36

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

    $ard(%'',%'',-'','',-','); 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 #include

  • 8/13/2019 Basic Functions of c Graphics

    5/36

    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.enum!er if points or +ertices and that is ( num - *. And another is an array ofpoints 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 drawpolyfunction than the first argument num is num!er of +ertices - that is 5 and thearray of polypoints contain num / elements so in rectangle num is 5 andpolypoint are 5 / 0 -1.

    http://2.bp.blogspot.com/-VnWXc9D_qGM/UUhOvC2CJlI/AAAAAAAAAio/HDOjojWAVTM/s1600/circle.png
  • 8/13/2019 Basic Functions of c Graphics

    6/36

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

    ! graphic program to demonstrate drawpolyfunction

    #include #include

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

    dra1pol2(&,points); getch(); closegraph();

    return ';

  • 8/13/2019 Basic Functions of c Graphics

    7/36

    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

    #include

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

    http://2.bp.blogspot.com/-TsVuhozdQ5w/UY_PqIltHrI/AAAAAAAAAnI/5rvrl0hf4yQ/s1600/drawpoly.png
  • 8/13/2019 Basic Functions of c Graphics

    8/36

  • 8/13/2019 Basic Functions of c Graphics

    9/36

  • 8/13/2019 Basic Functions of c Graphics

    10/36

    ! graphics program to demonstrate getmaxxfunction.

    #include

    #include

    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

    http://www.programmingcampus.com/2013/05/getcolor-function-in-c-graphics.htmlhttp://www.programmingcampus.com/2013/05/getcolor-function-in-c-graphics.htmlhttp://www.programmingcampus.com/2013/05/getcolor-function-in-c-graphics.htmlhttp://3.bp.blogspot.com/-SHpeAo2D5Q0/UaHk8tidukI/AAAAAAAAApc/ffUPg8oC-ak/s1600/getmaxx.pnghttp://www.programmingcampus.com/2013/05/getcolor-function-in-c-graphics.html
  • 8/13/2019 Basic Functions of c Graphics

    11/36

    graphic mode.

    General syntax of getmaxcolor function is :

    getmaxcolor();

    C graphics program to demonstrate the getmaxcolorfunction.

    #include #include

    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 ';

  • 8/13/2019 Basic Functions of c Graphics

    12/36

    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 GA dri+er and GA6I

    graphic mode.getmaxx functionis used to get the maximum +alue of 3

    coordinate on graphic screen usually it is '&4 for GA dri+er and GA6I

    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 getmaxyfunction.

    #include #include

    http://www.programmingcampus.com/2013/05/getmaxx-function-of-c-graphics.htmlhttp://2.bp.blogspot.com/-90Rq1cLTdNs/Uagec-IzJSI/AAAAAAAAArM/BtAo0kTfqME/s1600/getmaxcolor.pnghttp://www.programmingcampus.com/2013/05/getmaxx-function-of-c-graphics.html
  • 8/13/2019 Basic Functions of c Graphics

    13/36

    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 GA dri+er and GA6Igraphic mode.getmaxx functionis used to get the maximum +alue of 3

    coordinate on graphic screen usually it is '&4 for GA dri+er and GA6I

    graphics mode.

    General syntax of getmaxy function is:

    http://www.programmingcampus.com/2013/05/getmaxx-function-of-c-graphics.htmlhttp://3.bp.blogspot.com/-TfY4b0SmueM/UaHl8QLidrI/AAAAAAAAAps/UqRtWtD9xyY/s1600/getmaxy.pnghttp://www.programmingcampus.com/2013/05/getmaxx-function-of-c-graphics.html
  • 8/13/2019 Basic Functions of c Graphics

    14/36

    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 getmaxyfunction.

    #include

    #include

    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 ';

  • 8/13/2019 Basic Functions of c Graphics

    15/36

    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 #include

    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();

    http://www.programmingcampus.com/2013/05/moveto-function-in-c-graphic.htmlhttp://3.bp.blogspot.com/-TfY4b0SmueM/UaHl8QLidrI/AAAAAAAAAps/UqRtWtD9xyY/s1600/getmaxy.pnghttp://www.programmingcampus.com/2013/05/moveto-function-in-c-graphic.html
  • 8/13/2019 Basic Functions of c Graphics

    16/36

    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;

  • 8/13/2019 Basic Functions of c Graphics

    17/36

    #include#include

    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

    http://4.bp.blogspot.com/-UHoK3lGV_mA/UUOBAjNqCdI/AAAAAAAAAiI/Pc5wJnpFXk8/s1600/line.png
  • 8/13/2019 Basic Functions of c Graphics

    18/36

    using getxandgetyfunction. 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 functiontakes 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 linetofunction

    #include #include

    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 );

    http://www.programmingcampus.com/2013/05/moveto-function-in-c-graphic.htmlhttp://www.programmingcampus.com/2013/05/setlinestyle-function-of-c-graphic.htmlhttp://www.programmingcampus.com/2013/05/setlinestyle-function-of-c-graphic.htmlhttp://www.programmingcampus.com/2013/02/line.htmlhttp://www.programmingcampus.com/2013/05/moveto-function-in-c-graphic.htmlhttp://www.programmingcampus.com/2013/05/setlinestyle-function-of-c-graphic.htmlhttp://www.programmingcampus.com/2013/05/setlinestyle-function-of-c-graphic.htmlhttp://www.programmingcampus.com/2013/02/line.html
  • 8/13/2019 Basic Functions of c Graphics

    19/36

    >o+eto function is used with outtext

    function to display text or string at particular location on screen.

    C Graphic program to demonstratemo+eto function

    #include #include

    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 ';

  • 8/13/2019 Basic Functions of c Graphics

    20/36

  • 8/13/2019 Basic Functions of c Graphics

    21/36

    "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+ereffunction

    #include #include

    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 ';

  • 8/13/2019 Basic Functions of c Graphics

    22/36

    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 functionof c graphics.

    C graphic program to demonstrate pieslice function ofgraphics.h

    #include#include

    http://www.programmingcampus.com/2013/05/setfillstyle-function-in-c-graphic.htmlhttp://www.programmingcampus.com/2013/05/setfillstyle-function-in-c-graphic.htmlhttp://2.bp.blogspot.com/-HqXOdNv0U8U/Udge4MOJ8ZI/AAAAAAAAAzo/rv_Jqu9QT98/s1600/moveref.pnghttp://www.programmingcampus.com/2013/05/setfillstyle-function-in-c-graphic.html
  • 8/13/2019 Basic Functions of c Graphics

    23/36

    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)@

    ectangle 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 #include

    http://4.bp.blogspot.com/-MqR8EDIVPic/Ua1gA4yVsWI/AAAAAAAAArg/zvN5I9pm4Hc/s1600/pieslice.png
  • 8/13/2019 Basic Functions of c Graphics

    24/36

    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 yco$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

    http://4.bp.blogspot.com/-RVEE40kHFlk/UUSx3mYkppI/AAAAAAAAAiY/LHyNmbty2UM/s1600/rectangle.png
  • 8/13/2019 Basic Functions of c Graphics

    25/36

  • 8/13/2019 Basic Functions of c Graphics

    26/36

    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 int value

    BLACK 0

    BLUE 1

    GREEN 2

    CYAN 3

    RED 4

    MAGENTA 5

    BROWN 6

    LIGHTGRAY 7

    DARKGRAY 8

    LIGHTBLUE 9

    LIGHTGREEN 10

    LIGHTCYAN 11

    LIGHTRED 12

    LIGHTMAGENTA 13

    YELLOW 14

    WHITE 15

    C program to set !ackground

    #include #include

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

    set$color(%); getch(); closegraph();

  • 8/13/2019 Basic Functions of c Graphics

    27/36

  • 8/13/2019 Basic Functions of c Graphics

    28/36

    !HATCH_FILL 9

    INTERLEA"E_FILL 10

    WIDE_DOT_FILL 11

    CLOE_DOT_FILL 12

    UER_FILL 13

    'here are following color is a%ailable with

    setfillstyle function with its corresponding integer %alue.

    Color int value

    BLACK 0

    BLUE 1

    GREEN 2

    CYAN 3

    RED 4

    MAGENTA 5

    BROWN 6

    LIGHTGRAY 7

    DARKGRAY 8

    LIGHTBLUE 9

    LIGHTGREEN 10

    LIGHTCYAN 11

    LIGHTRED 12

    LIGHTMAGENTA 13

    YELLOW 14

    WHITE 15

    ! graphic program to demonstrate setfillstyle

    function

    #include #include

    int main( )

  • 8/13/2019 Basic Functions of c Graphics

    29/36

    { 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

    http://3.bp.blogspot.com/-4DF0PPq2ohw/UZES9ni--UI/AAAAAAAAAns/y-O0spXXaEo/s1600/setfillstyle.png
  • 8/13/2019 Basic Functions of c Graphics

    30/36

    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 int value

    OLID_LINE 0

    DOTTED_LINE 1

    CENTER_LINE 2

    DAHED_LINE 3

    UERBIT_LINE 4

    he second argument is to use !it pattern and last one is

    for lines thickness it can !e - pixel or & pixel wide.

    ! graphic program to demonstrate setlinestylefunction

    #include #include

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

    setlinest2le(%,%,%); line(%'',%'',-'',%'');

    setlinest2le(D@ABEDE,%,); line(%'',%&',-'',%&');

    setlinest2le(,%,%);

  • 8/13/2019 Basic Functions of c Graphics

    31/36

    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-sie);

    http://3.bp.blogspot.com/-jbUiGj0h8Jo/UY-rLTBiqAI/AAAAAAAAAm4/oaA_I8A_Kmc/s1600/setlinestyle.png
  • 8/13/2019 Basic Functions of c Graphics

    32/36

    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:ID

  • 8/13/2019 Basic Functions of c Graphics

    33/36

    outte7t72('',%',!?rogrammingcampus.com!);

    sette7tst2le(A@AAEFGGHT,BHFIDF,); 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

    usemo%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 demonstrateouttext function.

    http://www.programmingcampus.com/2013/05/moveto-function-in-c-graphic.htmlhttp://www.programmingcampus.com/2013/05/settextstyle-function-in-c-graphic.htmlhttp://3.bp.blogspot.com/-_cOx1_2pVLA/UYpTrPWExYI/AAAAAAAAAlE/uuTL-vlv-7c/s1600/settextstyle.pnghttp://www.programmingcampus.com/2013/05/moveto-function-in-c-graphic.htmlhttp://www.programmingcampus.com/2013/05/settextstyle-function-in-c-graphic.html
  • 8/13/2019 Basic Functions of c Graphics

    34/36

    #include #include

    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

    http://4.bp.blogspot.com/-Bew6yzax9K4/UYpLZLGLlxI/AAAAAAAAAkk/OFrnZ9YTdvk/s1600/outtext.png
  • 8/13/2019 Basic Functions of c Graphics

    35/36

  • 8/13/2019 Basic Functions of c Graphics

    36/36

    http://2.bp.blogspot.com/-FAQ2bn3ObpQ/UYpNZMXbpBI/AAAAAAAAAk0/_8VGklKaUhk/s1600/outtextxy.png