#!/usr/athena/bin/perl use strict; use Data::Dumper; $Data::Dumper::Indent = 0; my $carule = shift; my $width = shift; my $height = shift; my $rnd = 0; if ($#ARGV > -1) { $rnd = shift; } my $cline = []; for (my $i = 0; $i < $width; $i++) { $cline->[$i] = 0; } if ($rnd != 0) { for (my $i = 0; $i < $width; $i++) { if (rand (1) > $rnd) { $cline->[$i] = 1; } else { $cline->[$i] = 0; } } } else { $cline->[int ($width/2) - 1] = 1; } for (my $l = 0; $l < $height; $l++) { # print Dumper ($cline), "\n"; my $l = join ('', @{$cline}); $l =~ s/1/*/g; $l =~ s/0/ /g; print $l, "\n"; my $nline = next_line ($carule, $cline); $cline = $nline; } print "\n"; sub next_line { my $rule = shift; my $aref = shift; # print $rule, "\n"; my $brule_str = dec2bin ($rule); # print $brule_str, "\n"; my $brule = [split (//, $brule_str)]; # print "Brule == ", Dumper ($brule), "\n"; my $naref = []; my $val = 0; my $i = 0; $val = $val + ($aref->[$#{$aref}] * 4); $val = $val + ($aref->[$i] * 2); $val = $val + ($aref->[$i + 1]); my $nval = $brule->[7 - $val]; $naref->[$i] = ($nval eq '1' ? 1 : 0); for (my $i = 1; $i < $#{$aref}; $i++) { $val = 0; $val = $val + ($aref->[$i - 1] * 4); $val = $val + ($aref->[$i] * 2); $val = $val + ($aref->[$i + 1]); # print $val, "\n"; $nval = $brule->[7 - $val]; $naref->[$i] = ($nval eq '1' ? 1 : 0); } $i = $#{$aref}; $val = 0; $val = $val + ($aref->[$i - 1] * 4); $val = $val + ($aref->[$i] * 2); $val = $val + ($aref->[0]); $nval = $brule->[7 - $val]; $naref->[$i] = ($nval eq '1' ? 1 : 0); return $naref; } sub dec2bin { my $dec = shift; my $bin = sprintf ("%08b", $dec); return $bin; }