Created
December 1, 2011 16:29
-
-
Save moshen/1417991 to your computer and use it in GitHub Desktop.
Terminal Nyancat 256 color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use warnings; | |
use strict; | |
# Animation frames... | |
# Color ASCII escape sequences, gzipped and base64 encoded, because | |
# I thought 300 lines of animation frames was a little much. | |
my @frames = ( q( | |
H4sIAHywIU8AA+1d23XkOA797xT8oxBst+11z4QyMVQO+7ExbIAbydrdVXqCeJOEKNQZnzMURIq4 | |
BEAU6jb19M/b59/vfz/fnv78z8uvj9u0+zz98yUFrrI6PG473nX8wA/68cSYI+fze/hlNkvz9fWV | |
O7td9103p6kyJrq69vITeQTet6DIQY3X5094kXETYPclFS6ru37Q2w26k76jBJUPUPSHUF+vEvao | |
/djBVCQG0KHC1B540K2Exqve9jl9jbiVu7/9q2jih/EI2Ljj3tgIwp/DY2E41ZBJ7KcAJwtQjhUy | |
RnWGk1zDI9a1jZOz6OVbEZA+j/s91y0/C7soC0AeRvINC8GPAzobJOagYmOirKWMiEBzRHuL7upw | |
iOjO399lseP9Fx88cTcutj+PsQBwL0j4E9V9f5EThOShVxr1f9+i3zA56FEfteuZN8R1h+ciePBc | |
jz3cgSH9Uu+ZZmAMmRvvBj3SH5gfod5N9yQXhLtR8P0Z6i1PYwHVqA8jPSA70VtfUQUPJWx4kyPP | |
969nCpgQalyHRRY4zcF4tbug6umPzqYnotBRawDurjdIRkGN9T72NUxa//nx11+MAh6k6KIQWT6V | |
+AL8qKyHCjcFeCjfeuhqDHM1VJGWwI/Keui49VA8rWfmqmztS/GaUX7i2j6vkmrGzZA2iwp42m3b | |
UNDjqWkugmqyPrHp8Ue1YoY9eB6mvtmBUynhwEfiUE/hOtyqo8Fl9CV5fkhnQctZDxZ+kgExkI6r | |
oS+C7sO9uSjqWAvmmy8Cg2R/lwWnxhVRumoFeuBRSJVCRU7q9GONOoSvblE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yHSo0NG73LLYZNppYsJtvz83ZdqVjWws | |
oQNaVal1jNjLdPZ2X0qr7J1JnjuLcDh+HH3Om8BRTSdXIg6fdDiBGycd7tytspNQQuYzkiznKE6y | |
XE+y3L3PZYhykBcDwBUGM9SEi4+qfKmhJi1Bm22hBVlOvRzug7jPzGdW8V4dC117e1yY2jYjYeCE | |
C8q66SDdWGgkrpznJTRMdTwR8v6lMSyD7Ip0wOTFXUmcvLiRm8mLOwMvbp5+PEZZVfHUqRkYklZ4 | |
n4F315No5xZg3N85K9uPex9sGZNLFoQNuC7/o0bqLBWt0RmZddGpdGKiXR1q3TpARCKqdSDGwV7Z | |
9Cekwywc3c4tQca/BCTH7q7RDdqPx3yZLCqcGrc6AiBl3QgoOXhEkkaKdl+WfXZkP2pcKILeLiI0 | |
9ZRw1L4rMAaHoNklrw735O4MttO3lvX5oHwoyXQScbLlarLl7kEAtt0Alybir/mMNHkTez0Kg5u/ | |
msP31LzUUJPOoG0ssiY3T7067oO4z8x3VvG4eW+PC1PbZiQM6uCSxLtrcvEC8+OuSL5Lbl6KmQuW | |
3LxzNy/AzVt9ZQP6ilk4qklLmXrCTfwSPL6pUzMwJJ3w7sjGYTelP8mhJQQiQqhDUykGMGal4tck | |
466S1IIVQZPzYZg663tBPp7IM+tJtXNOxh3dYnkS7zeqOgZwVj6e2mjff2G4W385jDAPmIhzHy4O | |
h04vnBq3wgHAESqoeWp7HICq9/KMOhwhbrkDi4ZSz8qERxcqYDiW3hXIf+MzA1edVVncPOtnjbgY | |
v/zCtWPgL8YfSL11EWQjheBOIqJba8EdICIK/ymPx688gamFsXiLKcUCxNNShoDtu/WlifiLMEle | |
EOdsFsCaFAY3Vyrge2peaqiJ6lFQlgDbXWj+oXmAKrPyn9mP/wNvi7NrsNYCAA== | |
) ); | |
use Compress::Zlib; | |
use MIME::Base64; | |
use Time::HiRes qw( usleep gettimeofday ); | |
use Getopt::Long; | |
use Pod::Usage; | |
@frames = split("::\n", Compress::Zlib::memGunzip(decode_base64($frames[0]))); | |
my $options = {}; | |
GetOptions( "loop_times=i" => \$options->{loop_t}, | |
"run_seconds=i" => \$options->{run_s}, | |
"utf8" => \$options->{utf8}, | |
"help" => \$options->{help} | |
); | |
if( $options->{help} ){ | |
print_usage(); | |
} | |
sub print_usage { | |
pod2usage( { -message => $_[0] , -exitval => 1 , -verbose => 0 } ); | |
} | |
if( $options->{utf8} ){ | |
@frames = @frames[12..23]; | |
} else { | |
@frames = @frames[0..11]; | |
} | |
# Loop the animation per options set | |
my $loopcheck; | |
if( $options->{loop_t} ){ | |
$loopcheck = sub { | |
if( $options->{loop_t} ){ | |
$options->{loop_t}--; | |
return 1; | |
} else { | |
return 0; | |
} | |
}; | |
} elsif( $options->{run_s} ){ | |
my $runtime = gettimeofday(); | |
$loopcheck = sub { | |
if( (scalar(gettimeofday()) - $runtime) < $options->{run_s} ){ | |
return 1; | |
} else { | |
return 0; | |
} | |
}; | |
} else { | |
$loopcheck = sub { | |
return 1; | |
}; | |
} | |
# Clear the screen | |
print "\033[2J"; | |
# Animate! | |
while($loopcheck->()){ | |
my $frame = 0; | |
while($frame < 12){ | |
print "\033[0;0H"; # Jump to 0,0 | |
print $frames[$frame++]; | |
usleep(70000); | |
} | |
} | |
exit 0; | |
__END__ | |
=head1 NAME | |
nyan - Your very own animated terminal Nyancat! | |
=head1 SYNOPSIS | |
nyan [options] | |
Options: | |
--help|-h brief help message | |
--loop_times|-l number of times to loop the animation | |
--run_seconds|-r number of seconds to run the animation | |
--utf8|-u use utf8 half-blocks for pixels | |
If no options are specified, Nyancat will loop forever. | |
=head1 OPTIONS | |
=over 8 | |
=item --help|-h | |
Prints a brief help message and exits. | |
=item --loop_times|-l | |
Number of times to loop the Nyancat animation. | |
=item --run_seconds|-r | |
Number of seconds to run the Nyancat animation. | |
Note: This isn't exact. | |
=item --utf8|-u | |
Uses utf8 'half-block' characters to effectively double the | |
resolution in the terminal. May not display properly and | |
depends on the font used. | |
=back | |
=head1 DESCRIPTION | |
This is a port of nyan in the L<Image::Term256Color> perl distribution | |
so it can be run on it's own, without installing any perl modules. | |
It includes Nyancat animation frames within the script for enjoyment | |
on 256 color terminals. | |
=head1 EXAMPLES | |
Run it already: | |
nyan | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For a quick nyan, try:
curl https://gist.githubusercontent.com/moshen/1417991/raw/nyan.pl | perl
( orcurl https://gist.githubusercontent.com/moshen/1417991/raw/nyan.pl | perl - -u
for the unicode version. )Though... that does require a lot of trust...