954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help turbo c++ color text

Hello everyone ok straight to the point
i have to do this
a text or a word that is blinking and have color
and while it is blinking it is automatically changing its color
i know how to do a text with color and blinking but i don't know
how automatically changing while it is blinking or randomize the color...
Please help me i begging someone....

bobytch
Newbie Poster
8 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

Check out the functions rand() and srand() for randomization. You can use those functions to generate yourself some RGB values and then change the values of the text color to the generated values.
Show us some code of how you're planning to make the text blink, or change the color of the text maybe then more answers will follow.

Basteon
Newbie Poster
21 posts since Dec 2010
Reputation Points: 10
Solved Threads: 1
 

The only way I can think of to change the color of the text on every blink is to write a clock interrupt function and change the color in that function. Clock ticks about once every millisecond, so your interrupt function will want to make the change only once every 1,000 ticks. Turbo C++ may have a compiler-specific function to help you with that, I don't know.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Looks like this and this , with a new username.

Show us what you managed to figure out so far, so we only have to fill in the gaps (as opposed to giving you everything, which simply won't happen).

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 
#include <conio.h>
#include <stdio.h>
#include <graphics.h>

	int main()
	   {
	       textcolor(YELLOW + BLINK);
	       cputs("HELLO WORLD");
	       getch();
	       return 0;
	   }
bobytch
Newbie Poster
8 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

How about

int colours[3] = { RED, YELLOW, BLUE };
textcolor(colors[rand()%3] + BLINK);


Now add a loop around that, perhaps more colours in the array and maybe even a gotoxy and you're done.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

If you are going to do that then you don't need the BLINK attribute.

forever
   show text in color
   delay a few milliseconds
   erase text
   delay a few milliseconds
   generate another random color attribute
end of loop
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
int main()
{
int colors[3] = { RED, YELLOW, BLUE };{
textcolor(colors[rand()%3]+BLINK);
cprintf("HELLO WORLD");}
getch();
return 0;
}


OK HERE IS MY NEW CODE BUT I GOT ONE ERROR
FUNCTION 'RAND' SHOULD HAVE A PROTOTYPE
WHAT SHOULD I DO

bobytch
Newbie Poster
8 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

rand() is prototyped in stdlib.h

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<stdlib.h>
int main()
{
int colors[3] = { RED, YELLOW, BLUE };
textcolor(colors[rand()%3]+BLINK);
cprintf("HELLO WORLD");
getch();
return 0;
}


OK THIS IS WEIRD THE PROGRAM INITIATE
BUT IT IS ONLY IN ONE COLOR. WHAT IS WRONG IN
THIS CODE?? I HAVE NO IDEA.. THANKS FOR ALL THE REPLY

bobytch
Newbie Poster
8 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

You failed to use a loop, as explained in this and this posts

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

caps-lock-no-tnecessary-all-the-time.jpg .

Attachments caps-lock-no-tnecessary-all-the-time.jpg 27.75KB
Nick Evan
Not a Llama
Moderator
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
 

Off topic: @bobytch writing posts all in capital letters is considered as shouting and very rude. So please take it in consideration when you post next time

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

There is no loop. So you randomize the color only once, that is why you see only one color.

Tellalca
Posting Whiz in Training
209 posts since Mar 2010
Reputation Points: 29
Solved Threads: 24
 
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<stdlib.h>
int main()
{
loop:
int colors[3] = { RED, YELLOW, BLUE };
textcolor(colors[rand()%3]+BLINK);
gotoxy(1,5)
cprintf("HELLO WORLD");
goto loop;
getch();
return 0;
}


ok here is my new code again with loop but i have problem again
when i initiate the changing of color was superfast what should i do
sorry for the capslock..

bobytch
Newbie Poster
8 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

Ok This is solved i got i right thanks to everyone.....

bobytch
Newbie Poster
8 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

move line 7 down one line so that the color array is not re-initialized on every loop iteration. And you can get rid of that awful goto statement.

int colors[3] = { RED, YELLOW, BLUE };
while(1)
{
    textcolor(colors[rand()%3]+BLINK);
    gotoxy(1,5)
    cprintf("HELLO WORLD");
    delay(100); // slow down the loop
}
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: