Reputation: 183
I'm trying to write a program that draws a specific shape on the console screen. I want to try and use coordinate points off the console screen to specify points of the shape, store it in an array, and clearly show up on the console screen as a white (or any color) closed figure. I basically want to know whether it is possible to set up a Cartesian plane on the console screen in such a way I can creates shapes and figures depending on the (x,y) coordinates I provide the program.
I don't exactly understand how Windows GDI works, and the only library I've heard of that can do this is the 'curse.h' or 'ncurse.h' libraries. Besides I didn't find a single reference on the internet on how to install these different libraries in my Visual C++ 2010 Express Edition compiler. Thanks to @john, I was able to look up the console functions for Windows Application. I am a beginner with coding, so bear with me, here is a program I wrote based on that which is filled with errors (at least that's what the builder's saying):
#include <WinCon.h>
using namespace std;
int main()
{
char string[] = "#";
char recString[5] = {'\0'};
COORD coordinates;
coordinates.X = 15;
coordinates.Y = 10;
SetConsoleCursorPosition(GENERIC_READ, coordinates);
WriteConsole(GENERIC_WRITE, string, 1, recString, NULL);
char response;
cin >> response;
return 0;
}
Upvotes: 1
Views: 1952
Reputation: 29219
See this tutorial on how to draw primitive shapes using the Simple DirectMedia Layer (SDL) library with the SDL_gfx add-on library. This will draw on a window outside of the console window (AFAIK, it's not possible to draw pixel-by-pixel graphics directly inside the Windows console).
If you're just looking for a way to generate plots with geometric shapes in them, and you're already familiar with Matlab (or its free clone Octave), then you should consider using the excellent geom2d Matlab library.
Upvotes: 1
Reputation: 8027
The Windows Console API should give you everything you want http://msdn.microsoft.com/en-us/library/windows/desktop/ms682073%28v=vs.85%29.aspx
EDIT: I don't have much experience with this library but I can see some problems with the code above. Something like this is more like what you should be doing
HANDLE console_out = GetStdHandle(STD_OUTPUT_HANDLE);
...
SetConsoleCursorPosition(console_out, coordinates);
...
WriteConsole(console_out, string, 5, recString, NULL);
This page has some examples http://msdn.microsoft.com/en-us/library/windows/desktop/ms686971%28v=vs.85%29.aspx
Upvotes: 1