Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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; }

Replies are listed 'Best First'.
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?
[Corion]: erix: Ah. I use where 1 = 0 for queries where I only am interested in the structure ;)
[erix]: 1=0 is as short as TOP :)
[erix]: "code of someone that died" -- kinda nice if your code stops working too
[erix]: hard to implement, hmm
[Corion]: erix: Well, they also seem to have changed the server, or some software, or whatever, and seem to be in the process of changing the DB schema from having the "username" as primary key to something else.
[Corion]: Far too many things being done at once, or maybe only now has it become apparent that nobody knows that piece of software anymore

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2017-01-23 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (192 votes). Check out past polls.