Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

blinkenlights

by rattusillegitimus (Friar)
on Aug 15, 2002 at 04:58 UTC ( #190302=snippet: print w/replies, xml ) Need Help??
Description:

Recently, my wife (who knows I'm addicted to anything with blinking LEDs on it) suggested that I might hook a monitor to my headless Linux box and have it display just blinking lights in the screen. Once I tore myself away from staring at the modem and ethernet hub, I took a crash course in Curses and threw together the following script.

Of course, now I want to add more monitors to the box just to have more things blinking at me ;)

#!/usr/bin/perl -wT
use strict;
use Curses;
my $win = new Curses;
my ($x, $y, $color,$bold,$char);
initscr;
start_color;

# Initialize the 6 color pairs I'll use
init_pair 1, COLOR_GREEN,   COLOR_BLACK;
init_pair 2, COLOR_RED,     COLOR_BLACK;
init_pair 3, COLOR_YELLOW,  COLOR_BLACK;
init_pair 4, COLOR_BLUE,    COLOR_BLACK;
init_pair 5, COLOR_MAGENTA, COLOR_BLACK;
init_pair 6, COLOR_CYAN,    COLOR_BLACK;
init_pair 7, COLOR_BLACK,   COLOR_WHITE;
halfdelay(1);  #wait for 1/10 secs for keystroke
noecho;        #don't echo keystrokes

# Loop to continuously blink the lights
while (1) {
    $x = int(rand(79));
    $y = int(rand(23));
    $color = int(rand(8));  # use one of my 7 color pairs
    $bold = int(rand(2));
    # Use a space as my character
    $char = 32|COLOR_PAIR($color)|A_REVERSE;
    if ( $bold > 0 ) { $char = $char|A_BOLD; }
    $win->addch($y,$x,$char);
    $win->refresh;
    # exit loop when a key is pressed
    last unless ($win->getch() eq -1);
}
endwin;
Replies are listed 'Best First'.
BlinkenANSI
by Mr. Muskrat (Canon) on Aug 16, 2002 at 16:44 UTC
    The code looks nice but I couldn't get curses to install so... I wrote an ANSI version!
    #!/usr/bin/perl use strict; use warnings; use Term::ANSIScreen qw/:color :cursor :screen/; use Term::ReadKey; setmode 3; cls; my @colors = ('black on green', 'black on red', 'black on blue', 'black on yellow', 'black on cyan', 'black on magenta', 'black on white'); # Loop to continuously blink the lights but terminate when a key is pr +essed while (not defined (my $key = ReadKey(-1))) { locate int(rand(23)), int(rand(79)); print colored (" ", "reverse " . $colors[int(rand(7))]); }
    update: Uh, the reverse is not really necessary. I should try doing random foreground and background colors, display options and characters (you remember the high ascii block characters?).
Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://190302]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2021-03-07 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (121 votes). Check out past polls.

    Notices?