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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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

In reply to Re: Matrix falling text effect by zentara
in thread Matrix falling text effect by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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












    Results (70 votes). Check out past polls.

    Notices?