How can i slow this down?

Oct 2, 2008 at 8:07pm
Im jus playin around with this code, its supposed to give off the matrix effect ex. the running random symbols and numbers b4 the movie starts. So i kinda did it a generic way, but i want to know is there a way to slow down the letters, or the whole program? (and yes, it is supposed to be on an ifinite loop.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<iostream>
using namespace std;

int main()
{
    int entermatrix;
    
    cout << " Press 1 to enter the matrix 0.0 " << endl;
    cin >> entermatrix;
    switch (entermatrix){
           case 1:
                do
                {
                         cout << "A B   D   F   H   J   L   N   P   R   T U   W   Y  " << endl;
                         cout << "!   # $   ^ & * ( ) _   - = , . ; '   | ? 0 1   0 1" << endl;
                         cout << "a   c   e   g   i   k   m   o   q   s t   v   x   z" << endl;
                         cout << "1 2 3 4 5 6 7 8 9 0 0 1 2 3 4 5 6 7 8 9 0 1 0 1 1 0" << endl;
                         cout << "0 1   1 0 0   0 1 1 0   1 0 0 0 0 1   1 1 0 1 1   0" << endl;
                         cout << "1 0 0 0   1 1 0   0 1 1 0 1   1 0 0 0 0 0   0   1 1" << endl;
                         cout << "0 0 0 0   1 0 0 0 1   0 1 0 0 0 0   1 0 1 0 1 1 0 0" << endl;
                         
                         
                         }while(entermatrix==1);
                         
                         
                         
                         case 0:
                              
                              cout << "later" << endl;
                              break;
                              system("pause");
                              return 0;
                              }
                              }
Last edited on Oct 2, 2008 at 8:14pm
Oct 2, 2008 at 9:04pm
Use a delay function.

On Windows, #include <windows.h> and use VOID WINAPI Sleep( DWORD dwMilliseconds );
A millisecond is 1 000 = 1 second.

On POSIX systems, #include <unistd.h> and use void usleep( unsigned long microsec ); (BSD version. The SuSE version conforms to this one in use.)
A microsecond is 1 000 000 = 1 second.

Hope this helps.
Oct 2, 2008 at 11:16pm
Didnt work for me for some reason, the letters are still moving just as fast and the program doesnt seem slower by any means.
Last edited on Oct 2, 2008 at 11:16pm
Oct 2, 2008 at 11:55pm
use the thing you used to slow it down inside the do { } while loop.
Oct 3, 2008 at 2:35am
I did, maybe i have the format wrong.

VOID WINAPI Sleep( DWORD dwMilliseconds );
Last edited on Oct 3, 2008 at 3:06am
Oct 3, 2008 at 3:03am
This doesn't work?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <windows.h>

int main()
  {
  int letter = 'A';
  HANDLE hstdin = GetStdHandle( STD_INPUT_HANDLE );

  std::cout << "Press any key to quit\n";

  while (WaitForSingleObject( hstdin, 0 ) != WAIT_OBJECT_0)
    {
    std::cout.put( letter );
    if (++letter > 'Z') letter = 'A';
    Sleep( 50 );
    }
  FlushConsoleInputBuffer( hstdin );

  return 0;
  }
Oct 3, 2008 at 3:08am
That just compiles to a program that flashes and goes away. i took out return 0 but i dont know what else would make it close but ill say no.
Oct 3, 2008 at 8:45pm
There is something wrong with your development environment if it just flashes and disappears. That program will not terminate until you press a key.

[edit] To see if your IDE is simply pre-loading the input buffer, you can stick a copy of line 17 on line 8 and see if it still flashes.
Last edited on Oct 3, 2008 at 8:46pm
Oct 3, 2008 at 9:17pm
That essentially would be awsome, but i need a mix of symbols, letters and those letters and symbols scrolling in a downward fashion(or looking like it) with some parts broken to make the "effect"

In the program i made, everything is moving so fast that you cant tell what its supposed to be. so i wanted to slow it down so that the text itself (all text) is moving slower. not uber slow but slowly. theres only one good version of this that i found done in C# and i wanted to do it in C++

http://www.mediafire.com/?sharekey=f192bddc1e0676cdd2db6fb9a8902bda
^ not the one i downloaded, in fact he uses a pre-made font to do it, but covers essentially wat i want to try and do
Oct 3, 2008 at 10:16pm
Try adding a delay function at the end of the do using time.h or something, just make it hold for a second after all the couts. You shouldn't have to change your code that way.
Last edited on Oct 3, 2008 at 10:17pm
Oct 3, 2008 at 10:39pm
Hello again, i found a solution to my problem. Duoas, you were right about the sleep cmd but you should post how to use it correctly. no void or dword needs to be used:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<iostream>
#include<windows.h>

using namespace std;

int main()
{
    int entermatrix;
    
    cout << " Press 1 to enter the matrix 0.0 " << endl;
    cin >> entermatrix;
    
    switch (entermatrix){
           case 1:
                do
                {
                         
                         Sleep(2);
                         cout << "A B   D   F   H   J   L   N   P   R   T U   W   Y  " << endl;
                         cout << "!   # $   ^ & * ( ) _   - = , . ; '   | ? 0 1   0 1" << endl;
                         cout << "a   c   e   g   i   k   m   o   q   s t   v   x   z" << endl;
                         cout << "1 2 3 4 5 6 7 8 9 0 0 1 2 3 4 5 6 7 8 9 0 1 0 1 1 0" << endl;
                         cout << "0 1   1 0 0   0 1 1 0   1 0 0 0 0 1   1 1 0 1 1   0" << endl;
                         cout << "1 0 0 0   1 1 0   0 1 1 0 1   1 0 0 0 0 0   0   1 1" << endl;
                         cout << "0 0 0 0   1 0 0 0 1   0 1 0 0 0 0   1 0 1 0 1 1 0 0" << endl;
                         
                         
                         }while(entermatrix==1);
                         
                         
                         
                         case 0:
                              
                              cout << "later" << endl;
                              break;
                              system("pause");
                              return 0;
                              }
                              }

I got it slowed to where i want it now so rock on and thank you all!!
Last edited on Oct 3, 2008 at 10:40pm
Oct 4, 2008 at 12:12am
Glad you got it working.

But you should know, I am not obligated to post anything. What you got are function prototypes pulled right off of MSDN and the Linux man pages. You can expect to see such things when people answer questions, so you should learn to recognize them, not complain about how cut'n'pasting them didn't work. (Sorry. I just read what I wrote and it sounds a lot harsher than I meant it to be. Notice how I don't retract it though.)


In C and C++, all functions have a prototype, AKA a type, just like variables and constants and other data. A functions type is: what kind of thing it returns, and what kinds of things (and in what order) it takes as arguments. The compiler must know this information for you to use functions (well, to use them properly, at least). And the programmer usually needs to know it also.
Topic archived. No new replies allowed.