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; }


In reply to Some Silly Cyclic Cellular Automaton by YuckFoo

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.