Reputation: 91
I would like to know how to make a graphic rectangle in c (by that I mean a real rectangle, not just a bunch of asterisks). By the way, I can't use Borland's graphics.h.
Upvotes: 1
Views: 1524
Reputation: 1
we draw rectangle in borland compiler by using #include<graphics.h> use syntax-
rectangle(x1,y1,x2,y2);
x1,y1,x2 and y2 is the four coordinate of vertex of rectangle.
Upvotes: 0
Reputation: 43130
In a console window you can't draw lines (graphics) because the console is running
in text mode, you can display only ASCII characters.
The extended ASCII contains characters which can be used to display rectangles.
179 │
191 ┐
192 └
196 ─
217 ┘
218 ┌
Example
┌─────────┐
│ │
└─────────┘
In the above rectangle there are visible gaps between some characters
but in text mode these special chars are displayed differently, with no gaps.
Upvotes: 2
Reputation: 9671
There are several possible approaches. You can use API of your operating system (e.g. MS Windows API, or using Xlib API for many graphical environment using "X11"). But this is not a portable approach.
Then you can stick to a library that exists for several OS; examples of portable library that you can find on several OSs are the SDL library, cairo library, an OpenGL based library (maybe too much for 2D gfx, though you can use it too), GUI toolkits like Qt or GTK can help too, or even the GNU plot library, depending on exactly what you mean by graphic rectangle.
Likely the cairo library is the best fit to your problem.
Upvotes: 1