in it graph

Upload: ashwin-charles-a

Post on 07-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 In It Graph

    1/24

    GRAPHICS.H:

    To run Graphics program, you need graphics.h header file, graphics.lib library file andGraphics driver (BGI file) in the program folder. These files are part of Turbo C package. In allour programs we used 640x480 VGA monitor. So all the programs are according to that

    specification. You need to make necessary changes to your programs according to your screenresolution. For VGA monitor, graphics driver used is EGAVGA.BGI.

    In graphics mode, all the screen co-ordinates are mentioned in terms of pixels. Number of

    pixels in the screen decides resolution of the screen. For an example, circle is drawn with x-coordinate of the center 200, y-coordinate 100 and radius 150 pixels. All the coordinates are

    mentioned with respect to top-left corner of the screen.

    INITGRAPH:

    Initializes the graphics mode and clears the screen.

    Declaration:

    void far initgraph(int far *graphdriver, int far *graphmode, char far *pathtodriver);

    Remarks:

    y To start the graphics system, you must first call initgraph.y initgraph initializes the graphics system by loading a graphics driver from disk (or

    validating a registered driver) then putting the system into graphics mode.

    y initgraph also resets all graphics settings (color, palette, current position, viewport, etc.)to their defaults, then resets graphresult to 0.

    Arguments:

    *graphdriver: Integer that specifies the graphics driver to be used. You can give graphdriver a

    value using a constant of the graphics drivers enumeration type.

    *graphmode : Integer that specifies the initial graphics mode (unless *graphdriver = DETECT).

    If*graphdriver = DETECT, initgraph sets *graphmode to the highest resolution available for

    the detected driver. You can give *graphmode a value using a constant of the graphics_modes

    enumeration type.

    pathtodriver : Specifies the directory path where initgraph looks for graphics drivers (*.BGI)

    first.

    1.If they're not there, initgraph looks in the current directory.

    2. If pathtodriver is null, the driver files must be in the current directory.

  • 8/6/2019 In It Graph

    2/24

    This is also the path settextstyle searches for the stroked character font files (*.CHR).

    CLOSEGRAPH:

    closegraph() function switches back the screen from graphcs mode to text mode. It clears

    the screen also.

    Shutdown the graphic system.

    Declaration:

    Void far closegraph(void);

    Remarks:

    y Closegraph deallocates all memory allocated by the graphic system.y It then restores the screen to the mode it was in before you called initgraph.

    A graphics program should have a closegraph function at the end of graphics. Otherwise

    DOS screen will not go to text mode after running the program.

    Here, closegraph() is called after getch() since screen should not clear until user hits a

    key.

    ARC, CIRCLE, PIESLICE:

    y Arc draws a circular arc.y Circle draws a circle.y Pieslics draws and fills a circular pieslics.

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

    Remarks:

    arc draws a circular arc in the current drawing color.

    circle draws a circle in the current drawing color.

    pieslice draws a pie slice in the current drawing color, then fills it using the current fill

    pattern and fill color.

  • 8/6/2019 In It Graph

    3/24

    Arguments:

    (x,y): Center point of arc, circlew, or pie slice

    stangle: Start angle in degrees

    endangle: End angle in degrees

    radius: Radius of arc, circle, and pieslice

    Example c program of arc, circle, pieslice

    #include#include

    int main(){

    int gd = DETECT, gm;initgraph(&gd,&gm,"C:\\TC\\BGI");

    arc(100, 100, 0, 135, 50);/* (100, 100) are coordinates of center of the circle and 50 is the

    radius of circle.*/

    circle(100, 100, 50);pieslice(200,200,0,135,100);

    getch();closegraph();

    return 0;}

  • 8/6/2019 In It Graph

    4/24

    Output of program:

    ELLIPSE, FILLELLIPSE, SECTOR:

    y Ellips draws an elliptical arc.y Fillellipse draws and fills ellipse.y Sector draws and fills an elliptical pieslice

    Declarations :

    void ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius);

    void fillellipse(int x, int y, int xradius, int yradius);

    void sector( int x, int y, int stangle, int endangle, int xradius, int yradius);

    Remarks:

    y Ellipse draws an elliptical arc in the current drawing color.y Fillellipse draws an elliptical arc in the current drawing color and than fills it with

    fillcolor and fillpattern.

    y Sector draws an elliptical pie slics in the current drawing color and then fills it using thepattern and color defined by setfillstyle or setfillpattern.

    Ellipse is used to draw an ellipse (x,y) are coordinates of center of the ellipse, stangle is

    the starting angle, end angle is the ending angle, and fifth and sixth parameters specifies the Xand Y radius of the ellipse. To draw a complete ellipse strangles and end angle should be 0 and

    360 respectively.

    Argument:

    y (x,y)-coordinates of center of the ellipse,y xradius x radius of ellipse(Horizontal Axis)y yradius -y radius of ellipse (vertical Axis)y Stangle-Startinge Angley Endangle-Ending Angle

  • 8/6/2019 In It Graph

    5/24

    Example c program of ellipse

    #include#include

    int main(){int gd = DETECT, gm;

    initgraph(&gd, &gm, "C:\\TC\\BIN");

    ellipse(100, 100, 0, 360, 50, 25);

    fillellipse(100, 100, 50, 25);

    getch();closegraph();

    return 0;}

    Output of program:

    Example c program of sector:

    #include#include

    int main(){int gd = DETECT, gm;

    initgraph(&gd, &gm, "C:\\TC\\BIN");

    sector(100, 100, 0, 135, 25, 35);getch();

    closegraph();return 0;

    }

    Output of program:

    FLOODFILL :

    Flood-fills a bounded region

    Declaration :

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

    Remarks:

    y floodfill an enclosed areaon bitmap device.y The area bounded by the color border is flooded with the Current fill pattern and

    fill color.

  • 8/6/2019 In It Graph

    6/24

    y Use fillpoly instead of floodfill wherever possible so you can maintain codecompatability with future versions.

    y Floodfill does not work with the IBM-8514 driver.Arguments:

    y (x, y) is any point on the screen if (x,y) lies inside the area then inside will be filledotherwise outside will be filled,

    y border specifies the color of boundary of area.To change fill pattern and fill color use setfillstyle. Code given below draws a circle and

    then fills it.

    Example c program of floodfill:

    #include

    #include

    int main(){

    int gd = DETECT, gm;

    initgraph(&gd,&gm,"C:\\TC\\BGI");

    setcolor(RED);circle(100,100,50);

    floodfill(100,100,RED);

    getch();

    closegraph();return 0;

    }

    Output of program:

    In the above program a circle is drawn in RED color. Point (100,100) lies inside the circle as it is

    the center of circle, third argument to floodfill is RED which is color of boundary of circle. So

    the output of above program will be a circle filled with WHITE color as it is the default fill color.

  • 8/6/2019 In It Graph

    7/24

    GETCOLOR , SETCOLOR:

    y Getcolor returns the current drawing color.y Setcolor returns the current drawing color.

    Declaration:

    int getcolor(void);

    void far setcolor(int color);

    Remarks:

    y Getcolor function returns the current drawing color.e.g. a = getcolor(); // a is an int variableif current drawing color is WHITE then a will be 15.

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

    y To set a drawing color with setcolor,you canpass either the the color number or the equivalentcolor name.

    Example c program of getcolor

    #include

    #include

    int main(){

    int gd = DETECT, gm;int dwcolor;

    char a[100];initgraph(&gd,&gm,"C:\\TC\\BGI");

    dwcolor = getcolor();

    sprintf(a,"Current drawing color = %d

    ",dwcolor);outtextxy(0, 0, a);

    getch();

    closegraph();return 0;

    }

    Example c program ofsetcolor

    #include

    #include

    int main()

    {int gd = DETECT, gm;

    initgraph(&gd,&gm,"C:\\TC\\BGI");

    circle(100,100,50); /* drawn inwhite color */

    setcolor(RED);circle(200,200,50); /* drawn in

    red color */

    getch();closegraph();

    return 0;}

    SETCOLOR-PARAMETER

    COLOR VALUE

    BLACK 0

    BLUE 1GREEN 2

    CYAN 3

    RED 4

    MAGENTA 5

    BROWN 6

    LIGHTGRAY 7

    DARKGRAY 8

    LIGHTBLUE 9

    LIGHTGREEN 10

    LIGHTCYAN 11

    LIGHTRED 12LIGHTMAGENTA 13

    YELLOW 14

    WHITE 15

  • 8/6/2019 In It Graph

    8/24

    Output of setcolor:

    In Turbo Graphics each color is assigned a number. Total 16 colors are available. Strictlyspeaking number of available colors depends on current graphics mode and driver.For Example

    :- BLACK is assigned 0, RED is assigned 4 etc. setcolor function is used to change the currentdrawing color.e.g. setcolor(RED) or setcolor(4) changes the current drawing color to RED.

    Remember that default drawing color is WHITE.

    LINE ,LINEREL,LINETO:

    y Line draws a line between two specified points.y Linerel draws a line relative distance from current position(cp).y Lineto draws a line from the current position(cp ) to (x,y).

    Declaration :

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

    void far lineto(int x,int y);

    Remarks:

    y line draws a line from a point(x1,y1) to point(x2,y2) using current color,line style andthickness i.e. (x1,y1) and (x2,y2) are end points of the line.It does not update the current

    position(cp).

    y linerel function draws a line from the current position(CP) to a point that is a relativedistance (x, y) from the CP, then advances the CP by (x, y). You can use getx and gety to

    find the current position.

    y lineto function draws a line from current position(CP) to the point(x,y),then moves the cpto(x,y). you can get current position using getx and gety function.

    Return Value:

    y None

  • 8/6/2019 In It Graph

    9/24

    Example c program of line:

    #include#include

    int main(){int gd = DETECT, gm;

    initgraph(&gd,&gm,"C:\\TC\\BGI");

    line(100, 100, 200, 200);

    /* draws a line from (100, 100) to(200, 200).*/

    getch();

    closegraph();return 0;

    }

    Output of program:

    Example c program oflineto, linerel:

    #include

    #include

    int main(){

    int gd = DETECT, gm;

    initgraph(&gd,&gm,"C:\\TC\\BGI");

    moveto(100, 100);

    lineto(200, 200);

    moveto(250, 250);

    linerel(100, -100);

    getch();closegraph();

    return 0;}

    RECTANGLE, DRAWPOLY, FILLPOLY:

    Draws a rectangle in graphics mode.

    Declaration:

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

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

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

    Remarks:

    rectangle draws a rectangle in the current line style, thickness, and drawing color.

    To draw a square use rectangle with same height and width.

    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.

  • 8/6/2019 In It Graph

    10/24

    Arguments:

    (left,top) is the upper left corner of the rectangle, and (right,bottom) is its lower right corner.

    numpoints: Specifies number of points

    *polypoints:Points to a sequence of (numpoints x 2) integers. Each pair of integers gives the x

    and y coordinates of a point on the polygon.

    Numpoints indicates (n+1) number of points where n is the number of vertices in apolygon, polypoints points to a sequence of (n*2) integers . Each pair of integers gives x and y

    coordinates of a point on the polygon. We specify (n+1) points as first point coordinates shouldbe equal to (n+1)

    thto draw a complete figure.

    Return Value:

    yNone

    Example c program ofdrawpoly, fillpoly, rectangle:#include#include

    int main()

    {int gd = DETECT, gm;

    int points[] = { 320, 150, 420, 300, 250, 300, 320,150};

    /* points array contains coordinates of trianglewhich are (320, 150), (420, 300) and (250, 300). Note

    that last point(320, 150) in array is same as first. */

    initgraph(&gd, &gm, "C:\\TC\\BIN");

    drawpoly(4, points);fillpoly(4, points);

    rectangle(100,100,200,200);

    getch();

    closegraph();return 0;

    }

    Output of the program:

    SETLINESTYLESets the current line style and width or pattern

  • 8/6/2019 In It Graph

    11/24

    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.

    Enum: Line styles for getlinesettings and setlinestyle.

    Name Value Meaning

    SOLID_LINEDOTTED_LINE

    CENTER_LINEDASHED_LINE

    USERBIT_LINE

    01

    23

    4

    Solid lineDotted line

    Centered lineDashed line

    User-defined line style

    Enum: Line widths for getlinesettings and setlinestyle.

    Name Value Meaning

    NORM_WIDTH

    THICK_WIDTH

    1 : 1

    3 : 3

    pixel wide

    pixels wide

    SETFILLSTYLE , SETBKCOLOR:

    Declaration:

    void far setfillstyle(int pattern, int color);

    void far setbkcolor(int color);

    Remarks:

    setfillstyle sets the current fill pattern and fill color.

    setbkcolor sets the background to the color specified by color.

  • 8/6/2019 In It Graph

    12/24

    Example c program of setfillstyle

    #include#include

    int main(){int gd = DETECT, gm;

    initgraph(&gd, &gm, "C:\\TC\\BGI");

    setfillstyle(XHATCH_FILL, RED);circle(100, 100, 50);

    floodfill(100, 100, WHITE);

    getch();closegraph();

    return 0;}

    Output of program:

    BAR AND BAR3D :

    Declaration :-

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

    void bar3d(int left, int top, int right, int bottom, int depth, int topflag);

    Remarks:

    Bar function is used to draw a 2-dimensional, rectangular filled in bar . Coordinates ofleft top and right bottom corner are required to draw the bar.

    Arguments:

    y left specifies the X-coordinate of top left corner,y top specifies the Y-coordinate of top left corner,

    Setfillstyle- parameter (pattern)

    Names Value Means Fill With...

    EMPTY_FILL 0 Background colorSOLID_FILL 1 Solid fill

    LINE_FILL 2 ---

    LTSLASH_FILL 3 ///

    SLASH_FILL 4 ///, thick lines

    BKSLASH_FILL 5 \\\, thick lines

    LTBKSLASH_FILL 6 \\\

    HATCH_FILL 7 Light hatch

    XHATCH_FILL 8 Heavy crosshatch

    INTERLEAVE_FILL 9 Interleaving lines

    WIDE_DOT_FILL 10 Widely spaced dots

    CLOSE_DOT_FILL 11 Closely spaced dots

    USER_FILL 12 User-defined fill pattern

  • 8/6/2019 In It Graph

    13/24

    y right specifies the X-coordinate of right bottom corner,y bottom specifies the Y-coordinate of right bottom corner.y depth specifies the depth of bar in pixels,y topflag determines whether a 3 dimensional top is put on the bar or not ( if it is non-zero

    then it is put otherwise not ).

    Current fill pattern and fill color is used to fill the bar. To change fill pattern and fill color

    use setfillstyle.

    Example c program of bar and bar3d

    #include

    #include

    main(){

    int gd = DETECT, gm;

    initgraph(&gd,&gm,"C:\\TC\\BGI");

    bar(100, 100, 200, 200);bar3d(100, 100, 200, 200, 20, 1);

    getch();

    closegraph();return 0;

    }

    Output of program:

    CLEARDEVICE :

    Declaration :

    void cleardevice();

    Remarks:cleardevice function clears the screen in graphics mode and sets the current position to

    (0,0). Clearing the screen consists of filling the screen with current background color.

  • 8/6/2019 In It Graph

    14/24

    Example c program of cleardevice

    #include#include

    int main(){int gd = DETECT, gm;

    initgraph(&gd,&gm,"C:\\TC\\BGI");

    outtext("Press any key to clear the screen.");getch();

    cleardevice();outtext("Press any key to exit...");

    getch();

    closegraph();return 0;

    }

    Note : Don't use clrscr in graphics mode.

    GETBKCOLOR :

    Declaration :

    int getbkcolor();

    Remarks:

    getbkcolor function returns the current background colore.g. color = getbkcolor(); // color is an int variable

    if current background color is GREEN then color will be 2.

    Example c program of getbkcolor

    #include

    #include

    int main(){

    int gd = DETECT, gm;int bkcolor;

    char a[100];

    initgraph(&gd,&gm,"C:\\TC\\BGI");

  • 8/6/2019 In It Graph

    15/24

    bkcolor = getbkcolor();

    sprintf(a,"Current background color = %d",bkcolor);outtextxy(0, 0, a);

    getch();closegraph();return 0;

    }

    GETPIXEL,PUTPIXEL :

    y Getpixel gets the color of a specified pixel.y Putpixel places a pixel at a specified point.

    Declaration :

    int getpixel(int x, int y);

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

    Remarks:

    y Getpixel gets the color of pixel located at (x, y).y Putpixel plot a point in the color defined at location(x, y).

    Return:

    y getpixel returns the color of the given pixel present at location(x, y).y putpixel does not return.

    Example c program of getpixel,Putpixel

    #include

    #include

    int main(){

    int gd = DETECT, gm;int color;

    char array[50];

    initgraph(&gd,&gm,"C:\\TC\\BGI");

    color = getpixel(0, 0);sprintf(array,"color of pixel at (0,0) = %d",color);

    outtext(array);

  • 8/6/2019 In It Graph

    16/24

    /* As we haven't drawn anything on screen and by default screen is BLACK, thereforecolor of pixel at (0,0) is BLACK. So output of program will be color of pixel at (0,0) is 0, as 0

    indicates BLACK color.*/

    putpixel(25, 25, RED);

    // Output of this program will be a RED pixel on screen at (25, 25).

    /* For example if we want to draw a GREEN color pixel at (35, 45) then we will writeputpixel(35, 35, GREEN); in our c program, putpixel function can be used to draw circles, lines

    and ellipses using various algorithms.*/

    getch();closegraph();

    return 0;}

    GETX , GETY:

    Declaration :

    int getx();

    int gety();

    Remarks:

    getx function returns the X coordinate of current position. gety function returns the y coordinate of current position.

    Example c program of getx

    #include#include

    int main(){

    int gd = DETECT, gm;

    char array[100];

    initgraph(&gd, &gm, "C:\\TC\\BIN");

    sprintf(array, "Current position of x =

    %d",getx());outtext(array);

    getch();closegraph();

    return 0;}

    Example c program of gety

    #include#include

    int main(){

    int gd = DETECT, gm;

    char message[100];

    initgraph(&gd, &gm, "C:\\TC\\BIN");

    sprintf(message, "Current position of y =

    %d",gety());outtext(message);

    getch();closegraph();

    return 0;}

  • 8/6/2019 In It Graph

    17/24

    MOVETO, MOVEREL:

    Declaration :-

    void moveto(int x, int y);

    void moverel(int x, int y);Remarks:

    moveto function changes the current position (CP) to (x, y) moverel function moves the current position to a relative distance.

    Example c program ofmoveto:#include

    #include

    int main(){

    int gd = DETECT, gm;char msg[100];

    initgraph(&gd, &gm, "C:\\TC\\BIN");

    sprintf(msg, "X = %d, Y =

    %d",getx(),gety());

    outtext(msg);

    moveto(50, 50);

    sprintf(msg, "X = %d, Y = %d", getx(),gety());

    outtext(msg);

    getch();

    closegraph();return 0;

    }

    Example c program of moverel:

    #include

    #include

    int main(){

    int gd = DETECT, gm;int x, y;

    char message[100];

    initgraph(&gd, &gm, "C:\\TC\\BIN");

    moveto(100, 100);

    moverel(100, -100);

    x = getx();y = gety();

    sprintf(message, "Current x position =

    %d and y position = %d", x, y);outtextxy(10, 10, message);

    getch();

    closegraph();return 0;

    }

    OUTTEXT AND OUTTEXTXY FUNCTION:

    Declaration :

  • 8/6/2019 In It Graph

    18/24

    void outtext(char *string);

    void outtextxy(int x, int y, char *string);

    Remarks:

    y outtext function displays text at current position.y outtextxy function display text or string at a specified point(x,y) on the screen.

    Arguments:

    y x, y are coordinates of the point andy third argument contains the address of string to be displayed.

    Example c program of outtext:

    #include#include

    int main(){

    int gd = DETECT, gm;

    initgraph(&gd,&gm,"C:\\TC\\BGI");

    outtext("To display text at a particular position on the screen use outtextxy");outtextxy(100, 100, "Outtextxy function");

    getch();closegraph();

    return 0;}

    Do not use text mode functions like printf, gotoxy etc while working in graphics mode. Also note'\n' or other escape sequences do not work in graphics mode. You have to ensure that the text

    doesn't go beyond the screen while using outtext.

    PUTIMAGE :

    Declaration:

    void putimage(int left, int top, void *ptr, int op);

  • 8/6/2019 In It Graph

    19/24

    Remarks:

    putimage function outputs a bit image onto the screen. putimage puts the bit image previously saved with getimage back onto the screen,

    Arguments:

    y with the upper left corner of the image placed at (left, top).y ptr points to the area in memory where the source image is stored.y The op argument specifies a operator that controls how the color for each destination

    pixel on screen is computed, based on pixel already on screen and the corresponding

    source pixel in memory.

    SETTEXTSTYLE:

    Declaration :-

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

    Remarks:

    settextstyle function is used to change the way in which text appears, using it we canmodify the size of text, change direction of text and change the font of text.

    Argument:

    y font argument specifies the font of text,y Direction can be HORIZ_DIR (Left to top) or VERT_DIR (Bottom to top).

    Example c program of settextstyle:#include

    #include

    int main(){

    int gd = DETECT, gm;

    int x = 25, y = 25;int font = 0;

    initgraph(&gd,&gm,"C:\\TC\\BIN");

    for ( font = 0 ; font < 9 ; font++){

    settextstyle(font, HORIZ_DIR, 1);outtextxy(x, y, "Text with different fonts");

    y = y + 25;}

  • 8/6/2019 In It Graph

    20/24

    getch();

    closegraph();return 0;

    }

    Output:

    TEXTHEIGHT, TEXTWIDTH :

    Declaration :

    int textheight(char *string);

    int textwidth(char *string);

    Remarks:

    Textheight function returns the height of a string in pixels. Textwidth function returns the width of a string in pixels.

    Example c program of textheight

    #include

    #include

    int main()

    Example c program of textwidth

    #include

    #include

    int main()

  • 8/6/2019 In It Graph

    21/24

    {

    int gd = DETECT, gm;int height;

    char arr[100];

    initgraph(&gd, &gm, "C:\\TC\\BGI");

    height = textheight("C programming");

    sprintf(arr,"Textheight = %d",height);outtext(arr);

    getch();

    closegraph();return 0;

    }

    {

    int gd = DETECT, gm;int width;

    char arr[100];

    initgraph(&gd, &gm, "C:\\TC\\BGI");

    width = textwidth("programming");

    sprintf(arr,"Textwidth = %d",width);outtext(arr);

    getch();

    closegraph();return 0;

    }

    GRAPHDEFAULTS :

    Graphdefaults function resets all graphics settings to their defaults.

    Declaration :

    void graphdefaults();

    Remarks:

    It resets the following graphics settings :-

    y Sets the viewport to the entire screen.y moves the current position to (0,0).y sets the default palette colors, background color, and drawing color.y sets the default fill style and pattern.y sets the default text font and justification.

    C program of graphdefaults

    #include#include

  • 8/6/2019 In It Graph

    22/24

    int main(){

    int gd = DETECT, gm;

    initgraph(&gd, &gm, "C:\\TC\\BIN");

    setcolor(RED);setbkcolor(YELLOW);

    circle(250, 250, 50);

    /* we have first changed the drawing color to RED and background color to YELLOW

    and then drawn a circle with (250, 250) as center and 50 as radius. */

    getch();

    graphdefaults();/* When the user will press a key graphdefaults is called and both drawing and

    background color will be reset to their default values */

    getch();closegraph();

    return 0;}

    Basic Shapes and Colors:

    /*shapes.c*/

    #include

    #include

    void main()

    {

    int gd=DETECT, gm;

    int poly[12]={350,450, 350,410, 430,400, 350,350, 300,430, 350,450 };

    initgraph(&gd, &gm, "");

    circle(100,100,50);

    outtextxy(75,170, "Circle");

    rectangle(200,50,350,150);

    outtextxy(240, 170, "Rectangle");

    ellipse(500, 100,0,360, 100,50);

  • 8/6/2019 In It Graph

    23/24

    outtextxy(480, 170, "Ellipse");

    line(100,250,540,250);

    outtextxy(300,260,"Line");

    sector(150, 400, 30, 300, 100,50);

    outtextxy(120, 460, "Sector");

    drawpoly(6, poly);

    outtextxy(340, 460, "Polygon");

    getch();

    closegraph();

    }

    Sample Code to explain Moveto and Lineto:

    #include #include

    #include #include

    main( ){

    int gd = DETECT, gm ;char msg[80] ;

    initgraph ( &gd, &gm, "c:\\tc\\bgi" ) ;

    outtextxy ( 100, 0, "Demonstration of Moveto, Lineto, Moverel, Linerel" ) ;

    rectangle ( 0, 10, 639, 479 ) ;

    line ( 100, 50, 100, 350 ) ; /* draws a line */

    moveto ( 300, 50 ) ; /* moves the C.P. */

    lineto ( 300, 350 ) ; /* draws a line up to the point */

    moverel ( 200, -300 ) ; /* moves the C.P. by relative distance from its

    current position */linerel ( 0, 300 ) ; /* draws a line from the C.P. to a point a relative

    distance away from the current value of C.P. */

    outtextxy ( 104, 50, "( 100, 50 )" ) ;

  • 8/6/2019 In It Graph

    24/24

    outtextxy ( 104, 350, "( 100, 350 )" ) ;outtextxy ( 90, 375, "Line" ) ;

    outtextxy ( 304, 50, "( 300, 50 )" ) ;

    outtextxy ( 304, 350, "( 300, 350 )" ) ;

    outtextxy ( 280, 375, "Moveto, Lineto" ) ;

    outtextxy ( 504, 50, "( 500, 50 )" ) ;

    outtextxy ( 504, 350, "( 500, 350 )" ) ;outtextxy ( 480, 375, "Moverel, Linerel" ) ;

    getch( ) ;

    closegraph( ) ;restorecrtmode( ) ;

    }