Where the origin is
The first coordinate on the graphics screen is (0, 0), and it sits at the top-left corner of the drawing area. That is different from a standard Cartesian graph, where the origin usually appears at the bottom-left or center depending on the diagram.
Because of this, a point like (50, 50) is near the top-left. A point like (500, 400) is farther to the right and lower on the screen.
How x and y move on the screen
- X-coordinate: moves left to right.
- Y-coordinate: moves top to bottom.
This is the single biggest source of confusion. If you increase y, the object goes down, not up. That means if a rectangle or circle appears lower than expected, the y values are often the reason.
How to know the screen limits
You do not have to guess the last usable coordinate. graphics.h provides helper functions such as getmaxx() and getmaxy(). They return the largest visible x and y values for the current graphics mode.
int maxX = getmaxx();
int maxY = getmaxy();
This matters when you want to center a shape or place text near the bottom edge without hardcoding numbers that only work on one mode.
How common shape functions interpret coordinates
line(x1, y1, x2, y2)
line() draws between two absolute points. If you swap the endpoints, the same segment is drawn, but understanding each point still matters when you annotate a diagram.
rectangle(left, top, right, bottom)
rectangle() needs the left edge, top edge, right edge, and bottom edge. The words themselves tell you the intended order. If top is larger than bottom, your reasoning is already inconsistent.
circle(x, y, radius)
circle() uses the center point first, then the radius. So circle(320, 240, 60) means a circle centered at (320, 240) with radius 60.
outtextxy(x, y, text)
outtextxy() places the start of the text at the given coordinate. If labels look shifted, it is often because the coordinate marks the start point of the string, not the visual center of the sentence.
A simple coordinate demo program
This short example helps you visualize the screen directions immediately.
#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
setcolor(WHITE);
line(0, 0, 200, 0);
line(0, 0, 0, 150);
outtextxy(205, 0, "positive x");
outtextxy(0, 155, "positive y");
setcolor(YELLOW);
circle(120, 90, 30);
outtextxy(150, 90, "(120, 90)");
getch();
closegraph();
return 0;
}
The white lines show the positive directions. The yellow circle then makes it easy to see how a real object sits inside the coordinate space.
How to think about center points
If you want to place an object in the center of the screen, divide the maximum coordinates by two. That gives you the approximate center point:
int centerX = getmaxx() / 2;
int centerY = getmaxy() / 2;
Then use those values as the center for a circle or the reference point for text and animation. This is safer than memorizing one fixed coordinate from an old lab machine.
Common coordinate mistakes students make
- Thinking positive y goes upward. It does not.
- Using rectangle arguments as width and height. graphics.h wants corner coordinates, not size values.
- Assuming text is centered automatically. The x and y position marks where the text begins.
- Ignoring screen limits. A shape may exist, but part of it can fall outside the visible area.
Best way to practice this fast
Open the online compiler and draw the same object at three different coordinates. Move it right by increasing x. Move it down by increasing y. That hands-on repetition locks the system into memory much faster than memorizing a definition.