#!/usr/bin/perl # author: stray@stray.ch # version: 0.1 # description: a quick hack using perl and curses to display # blinkenlight movies (http://www.blinkenlights.de) # # usage: blinkenperl [-v] [-i] [-g] [-s ] # # -v displays frame and delay information # -i run interactive: scroll manually forwards and backwards # -s add characters between lights, default is 0. try 1. # -g attempt to draw some sort of grid. ugly. # # this needs curses. your mileage may vary. use Curses; use Getopt::Long; $space = 0; # default value for spacing between lights GetOptions('verbose' => \$verb, 'interactive' => \$inter, 'space=i' => \$space, 'grid' => \$grid ); &read_source($ARGV[0]); initscr(); noecho(); keypad(1); &make_colors(); #($w,$h) = GetTerminalSize(); $char[0] = " "; $char[1] = " "; $attr[0] = $BLACK; $attr[1] = $YELLOW; $w = 18; $h = 8; # just assume this for now $term_w = 80; $term_h =24; $top = 4; $left = ($term_w/2)-(($w*(1+$space))/2); $f = 0; while (1){ $f = 0 if ($f > $#del); $f = $#del if ($f < 0); $linenum = 0; foreach (@{$frames[$f]}) { $charnum = 0; foreach (@$_) { attron($attr[$_]); attron(A_BOLD|A_UNDERLINE) if ($grid && !$_); addstr($linenum+$top,$charnum+$left,$char[$_]); attroff(A_BOLD|A_UNDERLINE) if ($grid && !$_); attroff($attr[$_]); $charnum += 1+$space; } $linenum += 1+$space; } if ($verb) { move(2,2); deleteln(); insertln(); addstr(2,2,"Frame #$f / Delay $del[$f]"); } if ($inter) { addstr(2,40,"Interactive mode: use

and "); } refresh(); if ($inter) { undef $cmd; until ($cmd) { $key = getch(); if ($key eq "n") { $f++; $cmd = true; } if ($key eq "p") { $f--; $cmd = true; } } } else { select(undef,undef,undef,$del[$f]/1000); $f++; } } sub make_colors { start_color; init_pair 1, COLOR_GREEN, COLOR_GREEN; init_pair 2, COLOR_RED, COLOR_RED; init_pair 3, COLOR_BLUE, COLOR_BLACK; init_pair 4, COLOR_YELLOW, COLOR_YELLOW; init_pair 5, COLOR_BLACK, COLOR_BLACK; $GREEN = COLOR_PAIR(1); $RED = COLOR_PAIR(2); $BLUE = COLOR_PAIR(3); $YELLOW = COLOR_PAIR(4); $BLACK = COLOR_PAIR(5); } sub read_source { my $file = shift; open (F, $file) || die "Can't open $file: $!\n"; foreach $line () { chomp $line; chomp $line; $line =~ s/#.*//; next unless $line =~ /\S+/; if ($line =~ /^\@(\d+)/) { push(@del,$1); $frame = $#del; next; } push(@{$frames[$frame]}, [split(undef,$line)]); } close F; }