Colored text in graphics?

Hey!

I needed to know if there is any possible way to make a colorful text in graphics mode

Like each letter will have different colors

Try using setcolor(random(20));

Thanks :)
I'm not sure what you are asking. setcolor() is, I believe, the correct function to select the drawing color. (I haven't use the BGI graphics in ages.)

If your problem is that you are having trouble drawing individual letters in different colors, then there is no simple function to do that. You'll have to use outtextxy() and adjust the color correctly between each output.

You can align things properly by using textwidth() to find out how much space is needed between the start of the string and the current letter. Don't try to cache values -- font kerning can adjust things, so just pass the whole thing in.

An easy way would be to use a temporary string:

1
2
3
4
5
6
7
8
PSEUDOCODE

string temp;
for each (color, character) in (colors, text):
  setcolor( color );
  offset = textwidth( temp.c_str() );
  outtextxy( x + offset, y, character );
  temp += character;

Hope this helps.
Topic archived. No new replies allowed.