views:

485

answers:

2

Hi

I want to draw a filled box in console and set colour for every single pixel.

Is it possible to achive this with ncurses?

If not - is there any other library that will do the trick?

A: 

No, Curses is only for drawing characters, not pixels. If you want another libary, it depends the kind of language you want (C ? XLib, GTK... Java ? AWT, Swing) or if you only want a static image (libpng, svg, postscript...)

Pierre
+1  A: 

Seeing as how we're talking about pseudo-graphics in console, setting color for individual pixels is impossible with ncurses or any other library :-) so I'm going assume you meant setting colors for each character. That is possible with ncurses as long as your terminal supports colors. You need to invoke attron() function to specify color before you print the character and call attroff() to "unset" the color after character is printed. Prior to that, colors have to be set up for use:

start_color();
init_pair(1, COLOR_RED, COLOR_GREEN); /* create foreground / background combination */
attron(COLOR_PAIR(1)); /* use the above combination */
printw("Some text");
attroff(COLOR_PAIR(1)); /* turn color off */

Details are here

ChssPly76
To be clear, this solution sets the background color of the characters. This means that if you then print spaces, you will have exactly the empty filled box you want.
Jefromi