Posted: Tue Jun 06, 2006 9:39 pm Post subject: Perl Screensavers
Going with the knowledge that screensavers are simply EXE files with their extensions renamed to SCR... I started experimenting with compiling Perl into a screensaver.
Here's my test code:
Code:
#!/usr/bin/perl -w
# Notes:
# Values inside @ARGV:
# /p;593118 - The preview window for Display Properties tries showing the saver
# /c:3411052 - The "Settings" button was clicked
# /s - The "Preview" button was clicked OR the saver started on its own
use Tk;
use Tk::CursorControl;
# Load from config
my $txt = 'Screen Saver';
if (-e "C:/perlss.txt") {
open (TEXT, "C:/perlss.txt");
$txt = <TEXT>;
close (TEXT);
}
if (@ARGV && $ARGV[0] =~ /^\/c/i) {
my $main = MainWindow->new (
-title => 'Configure',
);
$main->Label (-text => 'Text:')->pack;
my $now = time();
while (1) {
$main->update;
select (undef,undef,undef,0.1);
$cursor->hide ($main);
if (time() - $now >= 2) {
my $color = (qw(limegreen cyan yellow white orange skyblue pink))[ int(rand(7)) ];
$lab->configure (-foreground => $color);
my $x = int(rand($main->screenwidth - $lab->width));
my $y = int(rand($main->screenheight - $lab->height));
$lab->place (-x => $x, -y => $y);
$now = time();
}
}
It loads a string from C:/perlss.txt to get the value for the main label that'll bounce around the screen (or defaults to "Screen Saver").
If the argument /c is provided (triggered by Display Properties when you click "Settings" for the screensaver), it pops up a small config window that lets you change the text.
Display Properties also tries to send a /p argument for the Preview Window, which is supposed to get your program to make something as a child window for the "computer monitor" icon. I'm not sure how well Perl can create child windows for another app, so I had it simply exit on this argument (showing a black screen as the preview).
Else, the screensaver executes as normal.
It opens a PerlTk window fullscreen with a black background, focusForces it to bring it to the top (above the task bar too). Then it creates a debugging widget that shows all the %ENV keys and the value of @ARGV.
Then uses Tk::CursorControl to hide the cursor on the mainwindow.
Then it binds <Motion> (mouse movements), <KeyPress> (any key being hit), and <Button> (mouse clicks) to all exit out of the program.
Then it creates the fun widget: a yellow-texted widget containing the text from C:/perlss.txt (which is configurable from Display Properties). From there, on 2 second intervals, the text moves all over the window while changing colors.
So, while this has pretty much nothing to do with bots, I thought it was pretty interesting anyway.
(I used PerlApp to compile it into an EXE and then just renamed it to SCR, and copied it to C:/Windows so that Display Properties could find it). _________________ Current Site (2008) http://www.cuvou.com/
That's a neat idea... the Bot-Depot screensaver could have like a black background and have a little window bouncing around with like the 10 or 15 most recently updated topics... and behind that would be other lil things bouncing around, like the Bot-Depot robot in the corner there or something.
edit
Or like the 10 or 15 posts could be in separate widgets (maybe colored a slightly darker shade of red or blue than the widget before it), and they'd start out offsetted a bit behind the widget before it, and they'd bounce around at the same velocity, so it'd look like a cool little trail effect. _________________ Current Site (2008) http://www.cuvou.com/
That's a neat idea... the Bot-Depot screensaver could have like a black background and have a little window bouncing around with like the 10 or 15 most recently updated topics... and behind that would be other lil things bouncing around, like the Bot-Depot robot in the corner there or something.
edit
Or like the 10 or 15 posts could be in separate widgets (maybe colored a slightly darker shade of red or blue than the widget before it), and they'd start out offsetted a bit behind the widget before it, and they'd bounce around at the same velocity, so it'd look like a cool little trail effect.
In the blue trail of posts would be the topic titles followed by the last poster and the time of post (or whatever info out of that is available in an RSS feed). For now they all say the same thing which is a hard-coded thing to use as an example.
In the screensaver, the blue trail starts out trailing from the top left corner, offsetted 50x70 pixels beyond the ones around it, and they all start off with a southeast velocity.
The robot actually comes in 5 different flavors. The robot starts in a random position traveling in a random direction. Each time it bounces off the edge of the screen, it changes colors. There's white (normal), red, blue, green, and yellow.
As far as configurable stuff will go... the color of the blue "snake" will be configurable as well as the text color on those labels. The speeds of the robot and the labels will be configurable as well (currently the bot travels at 5 pixels per tick and the labels travel 2 pixels).
All that's needed now is the RSS feed.
edit
Also any suggestions for the screensaver could be helpful at this point. Maybe a Matrix effect happening in the background? It all depends on how much Perl Tk can handle without eating a lot of CPU. _________________ Current Site (2008) http://www.cuvou.com/
Joined: 19 Jul 2004 Posts: 556 Location: Los Angeles, CA votes: 1
Posted: Thu Jun 08, 2006 6:32 pm Post subject:
One thought is that you may want to try this with win32::gui for a windows version, because it will be a lot smaller not having to include the full TK lib. Its a really sweet idea... keep it up. _________________ [ matt ]