Type writer effect...

This is a discussion on Type writer effect... within the C++ Programming forums, part of the General Programming Boards category; Probably been asked before, but does anyone know how to do a type writer effect? Like puts one letter at ...

  1. #1
    WhiteTiger
    Guest

    Type writer effect...

    Probably been asked before, but does anyone know how to do a type writer effect? Like puts one letter at a time until it spells a word? thanks

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    155
    I do it this way:

    Code:
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    int main(){
         char word[50] = "This is gonna be displayed slowly";
         slowtype(word);
    
         return 0;
    }
    
    
    void slowtype(char* word){
    
    	for (int i = 0; word[i] != '\0'; i++){
    		cout << word[i];                      //output a letter
    		Sleep(70);                            //wait for a small moment
    	}  //outputs text slowly
    	
    	Sleep(30);                         
    		   
    } //end void slowtype

  3. #3
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    I experimented with making it more random gaps...but rand doesn't like to work very randomly, so i did some crap to make the outcomes different....it's a littel better than using just rand....try it and see if you like it, there's plenty of room to improve but i only felt like spending 5 minutes:
    Code:
    #include <iostream>
    #include <windows.h>
    #include <conio.h>
    #include <time.h>
    using namespace std;
    
    char sentence[]="This is a sentence.";
    char * pointer=sentence;
    int timeToWait;
    int i;
    int x;
    int negate=0;
    int typeWriter(char*);
    
    int main()
    {
    	typeWriter(pointer);
    	getch();
    	return 0;
    }
    
    int typeWriter (char*)
    {
    	for (i=0;i<sizeof(sentence);i++)
    	{
    		timeToWait=0;
    		srand(unsigned(time(NULL)));
    		timeToWait=rand()%1000;
    		if (timeToWait<70)
    		{
    			timeToWait=70;
    		}
    		x=rand()%3;
    		if (x<1)
    		{
    			x=1;
    		}
    		switch (x)
    		{
    		case 1:
    			negate=0;
    			break;
    		case 2:
    			negate=1;
    			break;
    		}
    		if (negate==0)
    		{
    			timeToWait=timeToWait-200;
    		}
    		else
    		{
    			timeToWait=timeToWait+200;
    		}
    		Sleep(timeToWait);
    		std::cout<<sentence[i];
    	}
    	return 0;
    }
    im just crazy i guess
    PHP and XML
    Let's talk about SAX

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    30
    did you try randomize(); ?
    it makes random stuff a lot better.

  5. #5
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    >>randomize();

    im intrigued...tell me more
    PHP and XML
    Let's talk about SAX

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    30
    I think it is found in stdlib.h. Well its the one with the random command in it.

    Anyways, if you output a random number without using the randomize command in a program and run it twice, the number will be the same.

    Use "randomize();" in your code before the random function and the numbers will change. I think it sets them to an algorithim.

    This is the case with my compiler: Borland Turbo C++. Dunno what it does for the dev compiler, im guessing the same tho.
    Last edited by bc17; 11-23-2002 at 08:46 PM.

  7. #7
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    sounds like a compiler specific thing....
    mostly it sounds like it calls srand()
    I use srand(unsigned(time(null)));
    which sets the seed of rand with the internal clock so that it doesn't repeat numbers...but i noticed that mine repeat within a close range....is my calling srand more than once screwing it up or is that how i'm supposed to do it?
    PHP and XML
    Let's talk about SAX

  8. #8
    Shadow12345
    Guest
    srand(GetTickCount())

  9. #9
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    get tick tiem:
    what does taht do?
    PHP and XML
    Let's talk about SAX

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Segmentation Fault?
    By John_L in forum C Programming
    Replies: 10
    Last Post: 10-02-2007, 08:37 AM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21