Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,941 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,433 people online right now. Registration is fast and FREE... Join Now!




[C Graphics] blinking random colors

 
Reply to this topicStart new topic

[C Graphics] blinking random colors, except for black

ISAI
20 Jan, 2008 - 08:20 AM
Post #1

New D.I.C Head
*

Joined: 26 Dec, 2007
Posts: 41


My Contributions
I wrote this code so that random colors will appear on the text and "blink" every second(more or less),
but I can't seem to make it not blink *BLACK* , *BLACK*.
The code
CODE
if(color!=0)
is suppose to work, am I wrong?

Heres the entire code:

CODE
     while(color)
       {
       if(!kbhit())
     {
        randomize();
        color++;
        if(color!=0)
          {
            setcolor(color);
            delay(800);
            outtextxy(215,450,"Press any key to return");
            delay(800);
            setcolor(0);
            outtextxy(215,450,"Press any key to return");
          }
     }//if
       else
     {
        clearviewport();
        menu();
     }
       }//while

User is offlineProfile CardPM
+Quote Post

NickDMax
RE: [C Graphics] Blinking Random Colors
20 Jan, 2008 - 11:25 AM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,869



Thanked: 53 times
Dream Kudos: 550
My Contributions
I am not sure about the setcolor function, but I think that if you choose a color between 16 and 32 it should blink...

I am really not sure what you mean by:
QUOTE
I can't seem to make it not blink *BLACK* , *BLACK*.

User is offlineProfile CardPM
+Quote Post

ISAI
RE: [C Graphics] Blinking Random Colors
20 Jan, 2008 - 11:31 AM
Post #3

New D.I.C Head
*

Joined: 26 Dec, 2007
Posts: 41


My Contributions
QUOTE(NickDMax @ 20 Jan, 2008 - 12:25 PM) *

I am not sure about the setcolor function, but I think that if you choose a color between 16 and 32 it should blink...

I am really not sure what you mean by:
QUOTE
I can't seem to make it not blink *BLACK* , *BLACK*.



the setcolor function is a 16 numbers that equale different colors from 0 to 15.
and i meant by " *BLACK* , *BLACK* " that the random color will be black and the perm black : setcolor(0);
so it's something like this :
BLUE, BLACK
YELLOW, BLACK
GREEN, BLACK

getting my point?
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: [C Graphics] Blinking Random Colors
20 Jan, 2008 - 01:58 PM
Post #4

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,869



Thanked: 53 times
Dream Kudos: 550
My Contributions
So basically you just don't want the color to == 0.

I think you would do better to use a little mathematics:
CODE

while (!kbhit()) {
Color = (Color + rand(10)) % 15 + 1;
setcolor(Color);
...
}


The value Color in this loop will never be equal to 0 but will always have a value in the range 1 - 15 (0 - 14, then add 1 shifts it to 1 - 15).
User is offlineProfile CardPM
+Quote Post

ISAI
RE: [C Graphics] Blinking Random Colors
21 Jan, 2008 - 06:50 AM
Post #5

New D.I.C Head
*

Joined: 26 Dec, 2007
Posts: 41


My Contributions
QUOTE(NickDMax @ 20 Jan, 2008 - 02:58 PM) *

So basically you just don't want the color to == 0.

I think you would do better to use a little mathematics:
CODE

while (!kbhit()) {
Color = (Color + rand(10)) % 15 + 1;
setcolor(Color);
...
}


The value Color in this loop will never be equal to 0 but will always have a value in the range 1 - 15 (0 - 14, then add 1 shifts it to 1 - 15).


Ok thanks it works.
but another problem i seem to have is that i cannot re-enter the page i have this code in there.
theres a problem with the key entry i do.. it's as if the random key i press in order to return to the menu of the game is pressed always until i quit the game and run it again..
anyone has an idea how to fix this?

This post has been edited by ISAI: 21 Jan, 2008 - 06:59 AM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 04:43PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month