Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

blinkenlights

by rattusillegitimus (Friar)
on Aug 15, 2002 at 04:58 UTC ( [id://190302]=CUFP: print w/replies, xml ) Need Help??

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
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://190302]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2026-01-21 15:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (125 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.