Author Topic: [BASH] Nyan Cat Animation  (Read 7795 times)

0 Members and 1 Guest are viewing this topic.

Offline xzid

  • Knight
  • **
  • Posts: 329
  • Cookies: 41
    • View Profile
[BASH] Nyan Cat Animation
« on: October 04, 2011, 06:46:36 am »
Using bash I made a text "animation" of nyan cat. The 2nd link on google for "nyan cat ascii" led me here:

http://evilzone.org/creative-arts/nyan-cat-ascii/

Kudos to 10n1z3d

I added option for music in it, using either vlc or mplayer. Those lines are commented by default. Tested only with mplayer, but vlc should work.

Was made mostly as template for this type of thing. Wasted a good hour doing this.

Example Output:


Code: [Select]
#!/bin/bash

# config
IMGS=(
"
 +      o     +              o    \n\
     +             o     +       +\n\
 o          +                     \n\
     o  +           +        +    \n\
 +        o     o       +        o\n\
 -_-_-_-_-_-_-_,------,      o    \n\
 _-_-_-_-_-_-_-|   /\_/\          \n\
 -_-_-_-_-_-_-~|__( ^ .^)  +     +\n\
 _-_-_-_-_-_-_-\"\"  \"\"         \n\
 +      o         o   +       o   \n\
     +         +                  \n\
 o        o         o      o     +\n\
     o           +                \n\
 +      +     o        o      +   \n
" "
     o  +           +        +    \n\
 o          +                    o\n\
     o                 +          \n\
 +      o     +              o    \n\
  o     +        o               +\n\
 _-_-_-_-_-_-_-,------,  o      + \n\
 -_-_-_-_-_-_-_|   /\_/\    +     \n\
 _-_-_-_-_-_-_~|__( ^ .^)     o   \n\
 -_-_-_-_-_-_-_  \"\"  \"\"       \n\
 +      +     o        o      +   \n\
 o        +                o     +\n\
 +      o         +     +       o \n\
     +         +                  \n\
        +           o        +    \n
" )
REFRESH="0.5"
AUDIO_FILE="/tmp/nyan-cat.mp3"
# end

# count lines of first ascii picture in array
LINES_PER_IMG=$(( $(echo $IMGS[0] | sed 's/\\n/\n/g' | wc -l) + 1 ))

# tput $1 LINES_PER_IMG times, used for cuu1(cursor up) cud1(cursor down)
tput_loop() { for((x=0; x < $LINES_PER_IMG; x++)); do tput $1; done; }

# ^C abort, script cleanup
trap sigtrap INT
sigtrap()
    {
    # make cursor visible again
    tput cvvis

    # reset cursor
    tput_loop "cud1"

    # stop audio
    #kill `pgrep vlc`
    #kill `pgrep mplayer` 2&> /dev/null

    echo "caught signal SIGINT(CTRL+C), quitting ..."
    exit 1
    }

# need multi-space strings
IFS='%'

# start audio, vlc & mplayer examples
#vlc $AUDIO_FILE --quiet --loop --volume=100 &
#mplayer -really-quiet -loop 0 $AUDIO_FILE < /dev/null &

# hide the cursor
tput civis

# main loop, pretty self explanatory
while [ 1 ]; do for x in "${IMGS[@]}"; do
    echo -ne $x
    tput_loop "cuu1"
    sleep $REFRESH
done; done

# will never reach here, CTRL+C is required to quit

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: [BASH] Nyan Cat Animation
« Reply #1 on: October 04, 2011, 11:13:36 am »
Lolz! works on Ubuntu 10.04. Nice work :D

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: [BASH] Nyan Cat Animation
« Reply #2 on: October 04, 2011, 03:34:05 pm »
That is a nice one. Works well.

Offline gh0st

  • Sir
  • ***
  • Posts: 575
  • Cookies: 8
  • #DEDSec
    • View Profile
Re: [BASH] Nyan Cat Animation
« Reply #3 on: October 05, 2011, 12:34:00 am »
nyan cat ! cant belive it on batch I cannot run it tho Im on win but doesnt matter +1
http://www.youtube.com/watch?v=3TQbDz6-4eM&list=FLRPI0baZYq2BYMKf86elM8A&index=26

Offline Stackprotector

  • Administrator
  • Titan
  • *
  • Posts: 2515
  • Cookies: 205
    • View Profile
Re: [BASH] Nyan Cat Animation
« Reply #4 on: October 10, 2011, 07:38:57 am »
Wauw :D. looks good on my 22inch screen turned vertically
~Factionwars