The header file graphics.h contains moverel() function which moves a point from the current position(x_pos1, y_pos1) to a point that is at a relative distance (x, y) from the Current Position and then advances the Current Position by (x, y).
Note : getx and gety can be used to find the current position.
Syntax :
moverel(int x, int y);
The end position is calculated as :
x_pos2 = x_pos1 + x;
y_pos2 = y_pos1 + y;
Examples :
Input : x_pos1 = 0, y_pos1 =0, x = 200, y = 100
Output :
Input : x_pos1 = 100, y_pos1 = 150, x = 150, y = 60
Output :
CASE 1 : When the current position is at origin i.e, (0, 0)
Below is the implementation of moverel() function in C:
#include <graphics.h>
#include<stdio.h>
int main()
{
int gd = DETECT, gm;
char arr[100];
initgraph(&gd, &gm, "" );
moverel(200, 100);
sprintf (arr, "Current x position = %d and "
"y position = %d" ,getx(), gety());
outtextxy(100, 150, arr);
getch();
closegraph();
return 0;
}
|
Output :
CASE 2 : When the current position is other than origin(100, 150).
Below is the implementation of moverel() function in C:
#include <graphics.h>
#include<stdio.h>
int main()
{
int gd = DETECT, gm;
char arr[100];
initgraph(&gd, &gm, "" );
moveto(100, 150);
moverel(150, 60);
sprintf (arr, "Current x position = %d and "
"y position = %d" ,getx(), gety());
outtextxy(100, 150, arr);
getch();
closegraph();
return 0;
}
|
Output :
Last Updated :
29 Nov, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...