Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Some Silly Cyclic Cellular Automaton

by YuckFoo (Abbot)
on Dec 22, 2010 at 00:20 UTC ( #878380=CUFP: print w/ replies, xml ) Need Help??

Cyclic_cellular_automaton with a few changes.

Adjust $COLS and $ROWS for terminal size...

YuckFoo

#!/usr/bin/perl use strict; my $COLS = 80; my $ROWS = 60; my $SLEEP = .04; my $ITERS = 120; my @SCHEMES = ( ' ..::oo0088@@', ' .:o08@@80o:. ', '-<##>--<##>- ', ' .o@@@@@@@@o.', ' . o@o . o@o', '#### ++++ ', ); while(1) { my @chars = split('', $SCHEMES[rand(@SCHEMES)]); my $num = @chars; my $screen = new_screen($ROWS, $COLS, $num); my $backup = int(rand(2)); my $i; while ($i++ < $ITERS) { $screen = update($screen, $ROWS, $COLS, $num, $backup); show($screen, \@chars); select(undef, undef, undef, $SLEEP); } } #----------------------------------------------------------- sub update { my $s = shift; my $rows = shift; my $cols = shift; my $num = shift; my $back = shift; my $new; for my $r (0..$rows-1) { for my $c (0..$cols-1) { if (forward($s, $r, $c, $rows, $cols, $num)) { $new->[$r][$c] = ($s->[$r][$c] + 1) % $num; } elsif ($back) { $new->[$r][$c] = (($s->[$r][$c] - 1) + $num) % $num; } else { $new->[$r][$c] = $s->[$r][$c]; } } } return $new; } #----------------------------------------------------------- sub forward { my $s = shift; my $row = shift; my $col = shift; my $rows = shift; my $cols = shift; my $num = shift; for my $ri (-1..1) { my $r = ($row + $ri + $rows) % $rows; for my $ci (-1..1) { my $c = ($col + $ci + $cols) % $cols; ((($s->[$r][$c] + $num) - $s->[$row][$col]) % $num == 1) and return 1; } } return; } #----------------------------------------------------------- sub show { my $s = shift; my $chars = shift; for my $line (@$s) { print join('', map { $chars->[$_] } @$line), "\n"; } } #----------------------------------------------------------- sub new_screen { my $rows = shift; my $cols = shift; my $num = shift; my $s; for my $r (0..$rows-1) { for my $c (0..$cols-1) { $s->[$r][$c] = int(rand($num)); } } return $s; }

Comment on Some Silly Cyclic Cellular Automaton
Download Code
Re: Some Silly Cyclic Cellular Automaton
by McDarren (Abbot) on Dec 23, 2010 at 12:45 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://878380]
Approved by GrandFather
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2014-09-16 17:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (36 votes), past polls