#!/usr/local/bin/perl -w # # see also pepper.p pepperb.p pepperc.p # # wallpaper.p writes an image which I claim lempel ziv would not be good # at compressing # $pbmplot = 1 ; $pbmfile = "figs/wallpaperx.pbm" ; $pbmx = 400 ; $L = 50 ; # length of lines $d = 0.1 ; # density (rough) of black ink. No, I want the density of flipping events to be d. (along x or y) $pbmy = 100 ; $hprob = 0.5 ; $ascii = 1 ; # whether also to write an ascii summary to stdout. # eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; # $P = $pbmx * $pbmy ; $nlines = int(2.0 * $P * $d / $L) ; $r = $pbmx ; if ( $ascii ) { print "$pbmx $pbmy\n" ; print "$nlines $L\n" ; # } if ( $pbmplot ) { # note I actually write a pgm file . open (PBM,"> $pbmfile"); print PBM "P1\n# CREATOR: wallpaper.p DJCM 98 11 09\n" ; print PBM "$pbmx $pbmy\n" ; # print PBM "$maxpbm\n" ; } for ( $i = 1 ; $i <= $P ; $i ++ ) { $c[$i] = 0 ; } for ( $t = 1 ; $t <= $nlines ; $t ++ ) { do { $x = int ( rand() * $pbmx ) ; $y = int( rand() * $pbmy) ; $d = ( rand() < $hprob ) ? 1:0 ; # 1 = horizontal $i0 = $x + ($y-1) * $pbmx ; } while ( $c[$i0] ) ; # don't start where there is black ink already. if ( $ascii ) { $o = $d ; print "$x $y $o\n" ; } for ( $i = 1 ; $i <= $L ; $i ++ ) { $c[$i0] = 1 - $c[$i0] ; $i0 += ($d eq "1") ? 1 : $pbmx ; if ( $i0 > ( $r * $pbmy ) ) { $i0 = $i0 - $r * $pbmy ; } } } if ( $pbmplot ) { $tot = 0 ; $i0 = 0 ; for ( $i = 1 ; $i <= $pbmy ; $i ++ ) { for ( $j = 1 ; $j <= $pbmx ; $j ++ ) { $i0 ++ ; print PBM "$c[$i0] " ; $tot += $c[$i0] ; } print PBM "\n" ; } # bottom line close ( PBM ) ; print STDERR "$tot pixels high out of $P\n" ; } print STDERR "\n# xv $pbmfile\n" ;