#!/usr/local/bin/perl -w # # automaton.p writes an image which I claim lempel ziv would not be good # at compressing # # using a cellular automaton. # This is a nice one, made on keck: #automaton.p seed=34665235 ; xv figs/automaton346.pbm # $pbmplot = 1 ; $pbmfile = "figs/automaton.pbm" ; $pbmx = 400 ; $bias = 0.4 ; # initial fraction that are 1 $T = 100 ; $seed=123; $flip = 0.25 ; # prob of ink under CA rule $w = 5 ; # width of automaton window. # eval "\$$1=\$2" while $ARGV[0]=~ /^(\w+)=(.*)/ && shift; # $r = $pbmx ; $pbmy = $T; srand($seed) ; # make random cellular automaton foreach $i ( 0 .. (2**$w - 1) ) { $v = $i ; $b = "" ; foreach $m ( 1 .. $w ) { $d = $v % 2 ; $v = int ($v / 2) ; $b .= "$d" ; } print $b ; $ca{$b} = ( rand() < $flip ) ? 1:0; print " $ca{$b}\n" ; } if ( $pbmplot ) { # note I actually write a pgm file . open (PBM,"> $pbmfile"); if ( $T < $pbmy ) {$pbmy = $T ; } print PBM "P1\n# CREATOR: automaton.p DJCM 98 11\n" ; print PBM "$pbmx $pbmy\n" ; # print PBM "$maxpbm\n" ; } for ( $i = 1 ; $i <= $r ; $i ++ ) { $c[$i] = ( rand() > $bias ) ? 0 : 1 ; } &wrap_around ; sub wrap_around { for ( $ii = 1 ; $i <= $r + $w + 2 ; $i ++ , $ii ++ ) { $c[$i] = $c[$ii] ; } # } for ( $t = 1 ; $t <= $T ; $t ++ ) { for ( $i = 1 ; $i <= $r ; $i ++ ) { # print STDERR "$i : $c[$i] " ; print PBM "$c[$i] " ; # new state depends on this state and the next w. $con = ""; for ( $ii = 0 ; $ii < $w ; $ii ++ ) { $con .= "$c[$i+$ii]" ; } $c[$i] = $ca{$con} ; } &wrap_around ; print PBM "\n" ; } if ( $pbmplot ) { # bottom line close ( PBM ) ; } print STDERR "\n# xv $pbmfile\n" ;