-3

How can i make a train ascii to look like it's moving in the linux shell from right to left?

                                   _-====-__-____-============-__
                                 _(                             _)
                              OO(                               )_
                             0  (_                               _)
                           o0     (_                            _)
                          o         `=-___-===-_____-========-__)
                        .o                                _________
                       . ______          ______________  |         |      _____
                     _()_||__|| ________ |            |  |_________|   __||___||__
                    (         | |      | |            |  |Y_____00_|  |_         _|
                  /-OO----OO**=*OO--OO*=*OO--------OO*=*OO-------OO*=*OO-------OO*=P
Nir1612
  • 31
  • 1
  • 1
  • 4

3 Answers3

1

You could install the linux command 'sl' if you want trains running over your screen.

http://www.cyberciti.biz/tips/displays-animations-when-accidentally-you-type-sl-instead-of-ls.html

heldt
  • 4,166
  • 7
  • 39
  • 67
0

You should take a look at the ANSI Escape Codes, especially at moving the cursor and clearing the screen. For a quick start you can just clear \e[2J the entire screen and redraw everything.

Example:

#include <iostream>
using namespace std;

/* ASCII control character for ESCAPE (ESC) is "\e"
 * Alternatives: Oct 033, Dez 27, Hex 1B
 *
 * The '\e' escape sequence is not part of ISO C and many other language
 * specifications. However, it is understood by several compilers.
 * The Escape character can also be entered by pressing the "Escape" or
"Esc"
 * key on some systems.
 */

int main() {
    cout << "\e[35m" << "Purple\n" << "\e[m";
    // cout << "\e[2J\e[H" << "\e[35mPlease enter\e[m: \n";

    cout << "foo" << '\x2B' << "\n";
    return 0;
}

Or you use the library ncurses from GNU.

Peter
  • 2,240
  • 3
  • 23
  • 37
0

EDIT: You can use pr -tro width, original solution with expand beneath :

Put your ascii image in a file (train.txt), but remove the first spaces (that all lines have in common).

i=0
while [ $i -lt 20 ]; do
   clear
   cat train.txt | pr -tro $i
   sleep 1
   (( i = i + 1 ))
done

Solution with expand: Put your ascii image in a file (train.txt), but replace the first spaces (that all lines have in common) by 1 tab.

i=0
while [ $i -lt 20 ]; do
   clear
   cat train.txt | expand -$i
   sleep 1
   (( i = i + 1 ))
done

Alternative (oneliner image): use \r
Alternative for expand: use printf with a width in the formatstring.
Moving to the left: start with i=20 and use -gt 0 and (( i = i - 1 ))

Walter A
  • 19,067
  • 2
  • 23
  • 43