Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > another matrix thingy.

Reply
Thread Tools

another matrix thingy.

 
 
robin
Guest
Posts: n/a
 
      06-01-2005
#!/usr/bin/perl

srand;
$c=0;
while (1)
{
print " " x int rand (60);
print "| | |\n";
last if $c == 200;
$c++;
}


-r

 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      06-01-2005
robin wrote:
> #!/usr/bin/perl
>
> srand;
> $c=0;
> while (1)
> {
> print " " x int rand (60);
> print "| | |\n";
> last if $c == 200;
> $c++;
> }


I have no idea what purpose that code is supposed to fullfill nor what
if anything it has to do with the subject line.

There are, of couse, several things wrong with the code.

 
Reply With Quote
 
 
 
 
David K. Wall
Guest
Posts: n/a
 
      06-01-2005
Brian McCauley <> wrote:

> robin wrote:
>> #!/usr/bin/perl
>>
>> srand;
>> $c=0;
>> while (1)
>> {
>> print " " x int rand (60);
>> print "| | |\n";
>> last if $c == 200;
>> $c++;
>> }

>
> I have no idea what purpose that code is supposed to fullfill nor
> what if anything it has to do with the subject line.


The output is apparently supposed to look like the computer screens
from the movie "The Matrix".


> There are, of course, several things wrong with the code.


 
Reply With Quote
 
ewfalor@gmail.com
Guest
Posts: n/a
 
      06-01-2005


David K. Wall wrote:
> Brian McCauley <> wrote:
>
> > robin wrote:
> >> #!/usr/bin/perl
> >>
> >> srand;
> >> $c=0;
> >> while (1)
> >> {
> >> print " " x int rand (60);
> >> print "| | |\n";
> >> last if $c == 200;
> >> $c++;
> >> }

> >
> > I have no idea what purpose that code is supposed to fullfill nor
> > what if anything it has to do with the subject line.

>
> The output is apparently supposed to look like the computer screens
> from the movie "The Matrix".
>
>
> > There are, of course, several things wrong with the code.


I think that this looks a bit better.

#!/usr/local/bin/perl
#matrix.pl
#Wed Jun 1 15:56:43 MDT 2005
#
#
use warnings;
use strict;
use Time::HiRes qw( usleep );

srand;

for (my $c; $c <= 200; $c++){
print " " x int rand 60;
print "\033[32m|||\n";
usleep 500;
}
__END__

But there is so much that could be done with this.

 
Reply With Quote
 
thundergnat
Guest
Posts: n/a
 
      06-02-2005
wrote:
>
> David K. Wall wrote:
>
>>Brian McCauley <> wrote:
>>
>>
>>>robin wrote:


[snip code]

>>>I have no idea what purpose that code is supposed to fullfill nor
>>>what if anything it has to do with the subject line.

>>
>>The output is apparently supposed to look like the computer screens
>>from the movie "The Matrix".
>>
>>
>>
>>>There are, of course, several things wrong with the code.

>
>
> I think that this looks a bit better.
>


[snip code]

>
> But there is so much that could be done with this.
>


Hmm. I don't think *either* of those look terribly "Matrix-like".
Niether does this particularly, but it was entertaining to write.

#!/user/bin/perl

# Set the randomness to zero and you have Rain.
# Set the randomness low WRT Velocity and you have Swarm
# Set the randomness high WRT Velocity and you have Brownian Motion

use strict;
use warnings;
use Tk;

my $top = MainWindow->new();

my $maxobj = 50;
my $maxvel = 15;
my $run = 0;
my ($height,$width,$maxx, $maxy, $minx, $miny);
my @objects;
my @printable;
my $color = '';
my $randomness = 4;

$minx = $miny = 0;

for (20 .. 255){
push @printable, chr($_) if (chr($_) =~ /\p{Print}/);
}

my $canvas = $top->Canvas(
-background => 'black'
)->pack(-fill => 'both', -expand => 'y');

$top->bind('<Configure>' => sub {
$top->XEvent;
$maxx = $canvas->width - $minx;
$maxy = $canvas->height - $miny;
}
);

my $frame = $top->Frame->pack;

$frame->Label(
-text => 'Number of objects',
)->grid(-row => 1, -column => 0);

my $maxobjentry = $frame->Entry(
-textvariable => \$maxobj,
-width => 5
)->grid(-row => 1, -column => 1);


$frame->Label(
-text => 'Maximum Velocity'
)->grid(-row => 1, -column => 2);

my $maxventry = $frame->Entry(
-textvariable => \$maxvel,
-width => 5,
-validate => 'all',
-vcmd => sub{
if ($_[0] =~ /[^\d]+/){
return 0;
}else{
return 1;
}
}
)->grid(-row => 1, -column => 3);

$frame->Label(
-text => 'Randomness'
)->grid(-row => 1,-column => 4);

my $maxrandentry = $frame->Entry(
-textvariable => \$randomness,
-width => 5,
-validate => 'all',
-vcmd => sub{
if ($_[0] =~ /[^\d]+/){
return 0;
}else{
return 1;
}
}
)->grid(-row => 1,-column => 5);

$frame->Button(
-text => 'Start',
-command => sub{ $run = 1; setup(); run_it();},
-width => 6,
)->grid(-row => 1, -column => 6);

$frame->Button(
-text => 'Pause',
-command => sub{
$run = 0;
$maxobjentry->configure(-state => 'normal');
},
-width => 6,
)->grid(-row => 1, -column => 7);

$frame->Button(
-text => 'Resume',
-command => sub{ $run = 1; run_it(); },
-width => 6,
)->grid(-row => 1, -column => ;

my @letters = split //,'Not "The Matrix")';

for (0..$#letters){
$objects[$_]{object} = $canvas->createText((120+$_*1,100,
-text => $letters[$_],
-fill => 'light green',
-font => '-*-Courier-Medium-R-Normal--*-280-*-*-*-*-*-*'
);
}

$maxventry->bind($maxventry, '<Up>' => sub { $maxvel++ });
$maxventry->bind($maxventry, '<Down>' => sub { $maxvel-- });

$maxrandentry->bind($maxrandentry, '<Up>' => sub { $randomness++ });
$maxrandentry->bind($maxrandentry, '<Down>' => sub { $randomness-- });

$top->protocol('WM_DELETE_WINDOW' => sub{$run = 0, $top->update; $top->destroy});

MainLoop;

sub setup{
return unless $run;
$maxobjentry->configure(-state => 'disabled');
if (@objects){
for (@objects){
$canvas->delete($$_{object});
}
@objects = ();
}
my @fnames = qw/Times Hevatica Courier/;
for (0 .. $maxobj-1){
my $x = int(rand($maxx));
my $y = int(rand($maxy));
for (0 .. 2){
my $rgb = unpack('H*', pack('n', (int(rand(192)+64))));
$rgb =~ s/.+(\w\w)$/$1/;
$color .= $rgb;
}
my $font = '-*-'.$fnames[int(rand(2)+.5)].'-Medium-R-Normal--*-'.(int(rand(40)+20)*10).'-*-*-*-*-*-*';
$objects[$_]{velx} = 0;
$objects[$_]{vely} = int(rand($maxvel)+1);
$objects[$_]{object} = $canvas->createText($x, $y,
-text => $printable[int(rand(@printable))],
-fill => '#'.$color,
-font => $font
);
$color = '';
}
}
sub run_it{
while ($run) {
$maxvel = 0 if ($maxvel !~ /\d/);
$randomness = 0 if ($randomness !~ /\d/);
for(0 .. $#objects){
$objects[$_]{velx} += int(rand($randomness*2)+.5)-$randomness if $randomness;
$objects[$_]{vely} += int(rand($randomness*2)+.5)-$randomness if $randomness;

$objects[$_]{velx} = $maxvel if ($objects[$_]{velx} > $maxvel);
$objects[$_]{velx} = -$maxvel if ($objects[$_]{velx} < -$maxvel);
$objects[$_]{vely} = $maxvel if ($objects[$_]{vely} > $maxvel);
$objects[$_]{vely} = -$maxvel if ($objects[$_]{vely} < -$maxvel);

$canvas->move($objects[$_]{object}, $objects[$_]{velx}, $objects[$_]{vely});

my ($x,$y) = $canvas->coords($objects[$_]{object});

if ($x > $maxx){ $canvas->move($objects[$_]{object}, -$maxx,0) }
if ($x < $minx){ $canvas->move($objects[$_]{object}, $maxx,0) }
if ($y > $maxy){ $canvas->move($objects[$_]{object}, 0, -$maxy) }
if ($y < $miny){ $canvas->move($objects[$_]{object}, 0, $maxy) }
}
$top->update;
}
}
 
Reply With Quote
 
robin
Guest
Posts: n/a
 
      06-02-2005
wow....this is great.
I gotta learn more.
-robin

 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      06-03-2005
<fullquote>
robin wrote:
> wow....this is great.
> I gotta learn more.
> -robin

</fullquote>

What is great? It would be great if you would quote enough context such that
people could know what you are talking about.
Hopefully one of the first things you learn will be how to create Usenet
postings that other people can understand.

jue


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Matrix operations on character matrix element? Robert Kern Python 0 04-02-2009 12:27 AM
Re: Matrix operations on character matrix element? Terry Reedy Python 0 04-02-2009 12:12 AM
Matrix*Vector and Vector*Matrix Holgerson C++ 3 10-26-2007 07:38 AM
Matrix composed by two matrix lvcargnini VHDL 3 07-05-2006 07:21 AM
Re: Matrix DTS and Matrix 2 DTS? PeterTHX DVD Video 0 08-03-2003 05:46 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57