Re: [Dev-C++] "C" Numbers and Colors
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2005-10-29 11:12:46
|
To emit your color numbers as integers you have to multiply them with a
constant to increase them from the 0..1 range to span 0.255. Then you
typecast this value to an integer and use %u instead of %f to print them.
When it comes to colors, it all depends on which environment you are in.
If you print to a console supporting ANSI ESC sequences, you can use these
sequences to control the emitted color.
An example is:
printf("\x1b[1m\x1b[32mhello ");
printf("\x1b[32mthere ");
printf("\x1b[35mcolorful ");
printf("\x1b[0mworld\n");
However, the text console in Windows normally don't support the ESC
sequences, resulting in a very ugly printout.
More info about use of ANSI ESC sequences can be found at:
http://www.evergreen.edu/biophysics/technotes/program/ansi_esc.htm
If you are in a graphical environment, then there are normally better
output methods than printf, allowing control not just over color but over
font, printding direction, slanting, ...
Windows have a lot of attribute functions to control the output to the
currently selected DC (Device Context). SetTextColor() and SetBkColor()
are good functions too look a bit closer at :)
Remember that most Windows API have online-browseable documentation
available directly on the Microsoft web site.
/Per W
On Sat, 29 Oct 2005, Scott wrote:
> Newbie C, help...
>
> Is there a way to write the number as 255
> instead of 0.1 or 0.13434 etc.....
>
> sprintf(str, "R:%1.2f G:%1.2f B:%1.2f", color[0], color[1], color[2]);
>
> And also is it possible to change the text color?
>
> sprintf(str, "Red:%1.2f Green:%1.2f Blue:%1.2f", color[0], color[1], color[2]);
>
> I would like have Red (in red), Green in Green, and Blue text....
> Is this easy or possible to do in C?
>
> This function is obviosuly part of a 3D plugin, but it uses C commands,
> like sprintf....
>
> Cheers,
> Scott.
>
>
>
>
>
>
|