Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone help me improve upon this... Keep it simple if you can please...

use diagnostics; use strict; use Tk; my $colour = "black"; # title my $main = MainWindow->new(-title => "Matrix...", -bg => $colour,); # size of window $main->minsize(qw(422 200)); $main->maxsize(qw(422 200)); # icon in the top left corner of the window (system menu icon) my $file4o = "C:\\Perl\\tk\\prog2\\matx.gif"; # around 32x32 GIF or BM +P # add you own path ?!? Transparancy in gif not working for me ???? $main->idletasks; # necessary ! my $icon4options = $main->Photo(-file => $file4o); $main->iconimage($icon4options); # left side my $leftframe=$main->Frame(-bg => $colour,)->pack(-side=>'left', -fill +=>'y'); # $main Vs $leftframe my $matrix_textbox = $main->Text(-width => "2", -background => $colour +, -font => "-*-Matrix Code NFI-*-*-*--*-200-*", # hash out if y +ou don't have the font -foreground => "lightgreen", -wrap => "none", -relief => 'flat',)->pac +k(-side => 'right', -fill => 'y'); # A matric font can be found at +html?font_id=2555 my $matrix_textbox2 = $main->Text(-width => "2", -background => $colou +r, -font => "-*-Matrix Code NFI-*-*-*--*-200-*", # hash out if + you don't have the font -foreground => "lightgreen", -wrap => "none", -relief => 'flat',)->pac +k(-side => 'right', -fill => 'y'); # A matric font can be found at +html?font_id=2555 my $matrix_textbox3 = $main->Text(-width => "2", -background => $colou +r, -font => "-*-Matrix Code NFI-*-*-*--*-200-*", # hash out if +you don't have the font -foreground => "lightgreen", -wrap => "none", -relief => 'flat',)->pac +k(-side => 'right', -fill => 'y'); # A matric font can be found at +html?font_id=2555 my $a =("a\n"); my $b =("b\n"); my $c =("c\n"); my $d =("d\n"); my $e =("e\n"); my $f =("f\n"); my $g =("g\n"); my $H =("H\n"); my $i =("i\n"); my $j =("j\n"); my $l =("l\n"); my $n =("n\n"); my $o =("o\n"); my $r =("r\n"); my $s =("s\n"); my $hip =("\,\n"); my $w =("w\n"); my $y =("y\n"); my $space =("\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); my $onegap =(" \n"); sub five{ my @letters =($d, $l, $r, $o, $w, $onegap, $o, $l, $l, $e, $H, $space) +; my @letters2 =($n, $i, $a, $g, $a, $onegap, $o, $l, $l, $e, $H, $space +); my @letters3 =($onegap, $onegap, $onegap, $y, $o, $b, $onegap, $d, $a, + $b, $onegap, $onegap, $onegap, $onegap, $space); $matrix_textbox->Contents(@letters, @letters, @letters); $matrix_textbox2->Contents(@letters2, @letters2, @letters2); $matrix_textbox3->Contents(@letters3, @letters3, @letters3); $matrix_textbox->configure(-state => 'disabled',); $matrix_textbox2->configure(-state => 'disabled',); $matrix_textbox3->configure(-state => 'disabled',); $matrix_textbox->yviewScroll( 37,'units'); $matrix_textbox2->yviewScroll( 67,'units'); $matrix_textbox3->yviewScroll( 27,'units'); my $max = 27; # run through the below 27 times for (my $i=1; $i <= $max; $i++) { $matrix_textbox->yviewScroll( -1,'units'); $matrix_textbox2->yviewScroll( -2,'units'); $matrix_textbox3->yviewScroll( -1,'units'); $main->update; use Time::HiRes; Time::HiRes::sleep (.1 # ); } } ## repeat the above until I change $repeat to anything other than 0 ?? +?? my $repeat = 0; while ($repeat =~ /0/) {five;} # # Bits I'm after: # # To add a trailling and/or first/**** character brighter effect ??? # as of $matrix_textbox->configure(-foreground => "green",); only for +first/**** character of each @letters... ???? # sound effect ??? # disable the right click on scrolling text's popup. It's cursor chang +e too. # # crack pic over text (transparent gif over text) MainLoop;

READMORE tags added by Arunbear

Replies are listed 'Best First'.
Re: Matrix falling text effect
by thundergnat (Deacon) on Mar 11, 2006 at 22:43 UTC

    You would probably be better off using a canvas. Try something like this.

    Follow the bouncing Neo. :-)

      Thanks for the help guys... I'll take my time and go through your replys soon... Hopefully learning something. should of said 2: Am on Windows XP Home With ActiveState ActivePerl 5.8 Also use EnginSite Perl Editor LITE
        You should also check out Tk::Zinc, which is a canvas-on-steroids. It will allow you to make your text as a group, easily clone the groups and place them at different slots on the screen, and move them all as a group. That way, you can have the full-screen effect. I'll try to post an example later.

        I'm not really a human, but I play one on earth. flash japh
Re: Matrix falling text effect
by ayrnieu (Beadle) on Mar 11, 2006 at 21:37 UTC

    I rewrote your program before noting the "Bits I'm after" at the bottom -- I thought you wanted style suggestions. HTH, anyway.

    #! /usr/bin/env perl use diagnostics; use strict; use Tk; use Time::HiRes; my $BG_COLOUR = $ENV{MY_BG_COLOUR} || "black"; my $FONT = $ENV{MY_FONT} || "-*-Matrix Code NFI-*-*-*--*-200-*"; # my $GIF = $ENV{MY_GIF} || "C:\\Perl\\tk\\prog2\\matx.gif"; my %MATRIX = (hip => ",\n", space => "\n"x14, onegap => " \n"); $MATRIX{$_} = "$_\n" for qw/a b c d e f g H i j k l n o r s w y/; my $ITERATIONS = $ENV{MY_ITERATIONS} || 0; my $main = MainWindow->new(-title => "Matrix...", -bg => $BG_COLOUR); $main->minsize(qw(422 200)); $main->maxsize(qw(422 200)); $main->idletasks; # necessary ! $main->iconimage($main->Photo(-file => $GIF)); $main->Frame(-bg => $BG_COLOUR)->pack(-side => 'left', -fill => 'y'); # -------------------------------------------------------------------- +-- package MatrixBoxes; sub new { my @m; for (1..3) { push @m, $main->Text(-width => "2", -background => $BG_COLOUR, -font => $FONT, -foreground => "lightgreen", -wrap => "none", -relief => 'flat')->pack(-side => 'right', -fill => 'y'); } bless \@m; } sub Contents { my $m = shift; for (@$m) { $_->Contents(@{+shift}) } } sub configure { my $m = shift; for (@$m) { $_->configure(@_) } } sub yscroll { my $m = shift; for (@$m) { $_->yviewScroll(shift, 'units +') } } # -------------------------------------------------------------------- +-- package main; my $m = MatrixBoxes->new; sub five{ my @let1 = @MATRIX{qw/d l r o w onegap o l l e H space/}; my @let2 = @MATRIX{qw/n i a g a onegap o l l e H space/}; my @let3 = @MATRIX{qw/onegap onegap onegap y o b onegap d a b onegap + onegap onegap onegap onegap space/}; $m->Contents(\@let1, \@let2, \@let3); $m->configure(-state => 'disabled'); $m->yscroll(37, 67, 27); for (1..27) { $m->yscroll(-1, -2, -1); $main->update; Time::HiRes::sleep(0.1); } } five for 0..$ITERATIONS; MainLoop;
Re: Matrix falling text effect
by zentara (Archbishop) on Mar 12, 2006 at 14:47 UTC
    Here is a Zinc version. There are some things to watch out for when you use alot of timers and movement on screen. You don't want to overload your timers with work, or they won't be able to complete their task, before their next cycle. This results in nothing appearing on the screen. In this example, if I tried to move all columns in a single timer, it would overload, so I cheated, and shared columns between a few timers. There is also the relationship between timer speed, and pixels moved per cycle. You can choose a larger pixel movement per larger timer increment, but it will look jerky. This shows smooth motion. I also cheated a bit, by making it not resizable, so I could predict the number of columns. and hard code them into the timers. It is possible to do it so the screen could be any size, but I'll leave all that code-juggling up to you. :-) This should give you the basic idea.
      Have heard of Tk::Zink before zentara... and have tried to install it with a simple "instal Tk::Zinc" using the package manager thingy... Am a bit of an idot so I gave up on it after that didn't work. Could you give me some advice on installing it, so I can study you example. P.S. I looked at it befor, so that I could try to flip the main window(the whole thing/GUI maybe without the borders)... Is it suitable for that purpose 2?
        Sorry... But have found and installed Tk:Zinc and will work through it when am up and running)... The problem is now my version of perl itself I think. Getting this message: Tk::Zinc object version 804.027 does not match bootstrap parameter 800.024 at C:/perl/lib/ line 249 Am on a free perl version(get 800.024 from the "perl -MTk -e "print $Tk::VERSION") and am stuck on upgrading it? so any help now on upgrading