Created
June 16, 2020 20:12
-
-
Save cransom/722b71735809ea843bd07f8b04891c4f to your computer and use it in GitHub Desktop.
This file contains hidden or 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/perl -w | |
# $Id: krainthx,v 1.7 2003/04/14 20:00:33 spy Exp $ | |
# ben | |
#initialize color map and set counters | |
@colormap = (4,4, 7,7, 5,5, 8,8, 9,9, 3,3, 10,10, 11,11, 12,12, 2,2, 6,6, 13,13); | |
my $row = 0; | |
my $rainstate = 0; | |
my $badstate = 0; | |
# setup tmp filE | |
if ( -d "$ENV{'HOME'}/.tmp" ) { | |
$tmpdir = $ENV{'HOME'} . '/.tmp'; | |
} else { | |
$tmpdir = $ENV{'HOME'}; | |
} | |
$rainstatefile = $tmpdir . "/.rainstatefile"; | |
# this script requires that you manually create either ~/.tmp/.rainstatefile or ~/.rainstatefile if you dont have a .tmp directory. this prevents munging files that we shouldnt munge. | |
if ( -f $rainstatefile ) { | |
open(RAINSTATEFILE, "<$rainstatefile") or die "cant open $rainstatefile for reading, are you a moron?\n"; | |
while(<RAINSTATEFILE>) { | |
# print "debug: $_\n"; | |
if ($_ =~ /([0-9]+)/) { | |
$rainstate = $1; | |
} else { | |
$rainstate = 1; | |
$badstate = 1; | |
} | |
# print "rain: $rainstate bad: $badstate\n"; | |
} | |
close(RAINSTATEFILE); | |
if ($rainstate > 1000) { | |
$rainstate = 0; | |
} else { | |
$rainstate++; | |
} | |
} else { | |
# no rain state, just be 0 | |
$rainstate = 0; | |
} | |
$savestate = $rainstate; | |
while (<>) { | |
$line = $_; | |
for (my $i = 0; $i < length($line); $i++) { | |
$chr = substr($line, $i, 1); | |
$color = $i + $row + $rainstate; | |
$color = $color ? $colormap[$color %($#colormap-1)] : $colormap[0]; | |
print "\003$color" if $chr ne " " and $chr ne "\n"; | |
print "\26\26" if (ord($chr) >= 48 and ord($chr) <= 57) or ord($chr) == 44; | |
print $chr; | |
} | |
$savestate++; | |
$row++; | |
} | |
$savestate--; | |
open(RAINSTATEFILE, ">$rainstatefile") or die "omj. cant open $rainstatefile\n"; | |
print RAINSTATEFILE "$savestate"; | |
close(RAINSTATEFILE); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment