Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Matrix falling text effect

by zentara (Archbishop)
on Mar 12, 2006 at 14:47 UTC ( #536097=note: print w/replies, xml ) Need Help??


in reply to Matrix falling text effect

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.
#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Zinc; my $width = 400; my $height = 600; my %tgroups; my %scrollers; my $mw = MainWindow->new; $mw->protocol('WM_DELETE_WINDOW' => sub { &clean_exit }); $mw->geometry($width.'x'.$height); $mw->configure(-background => 'black'); $mw->resizable(0,0); $mw->fontCreate('medium', -family=>'courier', -weight=>'bold', -size=>int(-14*14/10)); my $zinc = $mw->Zinc(-width => $width, -height => $height, -backcolor => 'black', -borderwidth => 0, -relief => 'sunken', -cursor => "top_left_arrow", )->pack; #create a group with it's origin at 0,0 upper left corner $tgroups{0}= $zinc->add('group',1,-visible=> 1); $zinc->scale( $tgroups{0}, 1, -1); #reverse direction of y axis so # numbers increase going down #create some vertical text my @letters; foreach my $i(33..126,161..255){ push @letters, chr($i); } my @shuffled = map {$_->[0]} sort { $a->[1] <=> $b->[1]} map {[$_, rand(1)]} @letters; my $position = 0; foreach my $letter( @shuffled ){ $zinc->add( 'text', $tgroups{0} , -position => [ 0, $position ], -text => $letter, -font => 'medium', -color => 'green', -priority => 2, ); $position += 15; } ################################################### #clone and translate # get width of column considering font my @pos = $zinc->bbox( $tgroups{0} ); #(corner coords x,y,x1,y1) my $widthcol = $pos[2] - $pos[0] + 10; # add a 5 pixel border my $numcols = int($width/$widthcol) + 1; #20 cols foreach my $j(1..$numcols){ $tgroups{$j} = $zinc->clone( $tgroups{0} ); $zinc->translate($tgroups{$j}, $j * $widthcol, int rand($height/8) ) +; } #start scroll &scroll; MainLoop; ########################################################## sub clean_exit{ foreach my $scroller(keys %scrollers){ $scrollers{$scroller}->cancel; } undef $zinc; $mw->destroy; Tk::exit; } ######################################################## sub scroll { $scrollers{0} = $mw->repeat(25,sub { foreach my $key(0,5,10,15,20 ){ $zinc->translate($tgroups{ $key },0, 5 ); my @pos = $zinc->bbox( $tgroups{$key} ); #(corner coo +rds x,y,x1,y1) if($pos[1] > $height/2){ $zinc->itemconfigure($tgroups{$key}, -visible => 0); $zinc->translate($tgroups{$key}, 0, (-$pos[3] )); $zinc->itemconfigure($tgroups{$key}, -visible => 1); } } } ); $scrollers{1} = $mw->repeat(20,sub { foreach my $key(1,4,6,11,16,19){ $zinc->translate($tgroups{ $key },0,5); my @pos = $zinc->bbox( $tgroups{$key} ); #(corner coo +rds x,y,x1,y1) if($pos[1] > $height){ $zinc->itemconfigure($tgroups{$key}, -visible => 0); $zinc->translate($tgroups{$key}, 0, (-$pos[3] )); $zinc->itemconfigure($tgroups{$key}, -visible => 1); } } } ); $scrollers{2} = $mw->repeat(30,sub { foreach my $key(2,7,9,12,14,17){ $zinc->translate($tgroups{ $key },0,5); my @pos = $zinc->bbox( $tgroups{$key} ); #(corner coo +rds x,y,x1,y1) if($pos[1] > $height){ $zinc->itemconfigure($tgroups{$key}, -visible => 0); $zinc->translate($tgroups{$key}, 0, (-$pos[3] )); $zinc->itemconfigure($tgroups{$key}, -visible => 1); } } } ); $scrollers{3} = $mw->repeat(36,sub { foreach my $key(3,8,13,18){ $zinc->translate($tgroups{ $key },0,5); my @pos = $zinc->bbox( $tgroups{$key} ); #(corner coo +rds x,y,x1,y1) if($pos[1] > $height){ $zinc->itemconfigure($tgroups{$key}, -visible => 0); $zinc->translate($tgroups{$key}, 0, (-$pos[3] - $height) +); $zinc->itemconfigure($tgroups{$key}, -visible => 1); } } } ); return; }

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^2: Matrix falling text effect
by Anonymous Monk on Mar 13, 2006 at 11:54 UTC
    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 http://zentara.net/zinc/(Hopefully 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/DynaLoader.pm 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
        That means you have the older version of Tk, and probably Perl5.6. That was the current version around 18 months ago. Tk jumped it's version values from 800.024 to 804.027( I know it's weird, but it was done that way to reflect the underlying tcl libs)

        Get the latest 5.8.8 ActiveStatePerl version and upgrade your Perl. Then Zinc should install fine.


        I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (1)
As of 2022-01-26 08:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (69 votes). Check out past polls.

    Notices?