Thread: ascii animation

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    8

    ascii animation

    i would like to add some simple ascii animation to my application. i've seen it done with other linux based console apps (which is what mine is). Here is an example; the user loads the app...

    [example]

    [jstn@twinturbo]& someapplication

    Loading configuration files... [animation here]

    Settings loaded!

    [/example]

    the animation looks like { | \ - / } except the printing is done in one space on the screen, as to give the affect that the slash is spinning. can anyone give me a snippet of code to do this in linux, and does it require you to clear the screen? i'm using gcc 3.0.4 to compile this program. thanks!

    -jstn

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You might want to try in the Linux forum....
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    The code to do the animation is very simple:
    Code:
    #include <stdio.h>
    #include <time.h>
    
    void sleep ( long milli )
    {
      clock_t end, current = clock();
      for( end = current + milli; current < end; current = clock() );
    }
    
    int main ( void )
    {
      int x = 0;
      const char *barRotate = "|\\-/";
      printf ( "Loading configuration files... " );
      for ( ; ; ) {
        if ( x > 3 ) x = 0;
        printf ( "%c\b", barRotate[x++] );
        sleep ( 200 );
      }
      return 0;
    }
    You may have to create a separate process to run the animation and perform other work at the same time, this is bare bones.

    -Prelude
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    8
    great - thanks for your help Prelude.

    -jstn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  2. Office access in C/C++ NOT VC++!! :)
    By skawky in forum C++ Programming
    Replies: 1
    Last Post: 05-26-2005, 01:43 PM
  3. Animation class not working
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 03-02-2005, 06:48 AM
  4. ascii values for keys
    By acid45 in forum C Programming
    Replies: 2
    Last Post: 05-12-2003, 07:13 AM
  5. Checking ascii values of char input
    By yank in forum C Programming
    Replies: 2
    Last Post: 04-29-2003, 07:49 AM