Open In App

lineto() function in C

Last Updated : 04 Dec, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The header file graphics.h contains lineto() function which draws a line from current position to the point(x,y). Note : Use getx() and gety() to get the current position. Syntax :
lineto(int x, int y);

where,
(x, y) are the coordinates upto which the
line will be drawn from previous point.
CASE 1 : When the initial position of point is (0,0) Below is the implementation of lineto() function with initial position at origin : C
// C Implementation for lineto()
#include <graphics.h>

// driver code
int main()
{
    // gm is Graphics mode which is
    // a computer display mode that
    // generates image using pixels.
    // DETECT is a macro defined in
    // "graphics.h" header file
    int gd = DETECT, gm;

    // initgraph initializes the
    // graphics system by loading a
    // graphics driver from disk
    initgraph(&gd, &gm, "");

    // lineto function
    lineto(250, 100);

    getch();

    // closegraph function closes the
    // graphics mode and deallocates
    // all memory allocated by
    // graphics system .
    closegraph();

    return 0;
}
Output :

CASE 2 : When the initial position of point is not (0, 0) Below is the implementation of lineto() function with initial position other than origin : C
// C Implementation for lineto()
#include <graphics.h>

// driver code
int main()
{
    // gm is Graphics mode which is
    // a computer display mode that
    // generates image using pixels.
    // DETECT is a macro defined in
    // "graphics.h" header file
    int gd = DETECT, gm;

    // initgraph initializes the
    // graphics system by loading a
    // graphics driver from disk
    initgraph(&gd, &gm, "");

    // change initial position of point
    // with moveto function
    moveto(100, 100);

    // lineto function
    lineto(250, 100);

    getch();

    // closegraph function closes the
    // graphics mode and deallocates
    // all memory allocated by
    // graphics system .
    closegraph();

    return 0;
}
Output :


Next Article
Practice Tags :

Similar Reads