#!/usr/local/bin/perl -w # # tartan disc drawer # # this is the one to use. ? nop, maybe tartan2.p . see tartan.README # usage: to make all in tartan1.pbm (in images/figs) # tartan2.p c=1 all=3 #(run this in ~/images) # for the latest design, # tartan.p c=1 all=3 circle2=0 # $spacious=1; # whether to space things out a bit more. $circle = 1 ; # whether to exclude points outside circle $circle2 = 1 ; # whether to exclude points inside circle2 $repeat = 3 ; # number of times to periodic $pbmplot = 1 ; $pbmfile = "figs/tartan" ; $pbmx = 286 ; # for width=6, 4 more than mult of 6 $pbmx = 202 ; # for width=8, mult of 8 plus 2 $pbmx = 276 ; # for width=12, $c = 1 ; # colour (1,2,3) or 1 for all $all = 3 ; # set to zero to force only one colour $ascii = 1 ; # whether also to write an ascii summary to stdout. $low = 0 ; $high = 1 - $low; $xoff = 0.35 ; # offset of centre of circle $yoff = 0.42 ; $ex = 0.41 ; $ey = 0.56 ; # fraction of the whole repeated picture $efx = 0.11 ; # was .1,.13 ellipticity (stretch by sqrt 1/this) along x dirn $re = 0.053 ; # radius in the y direction # was .05 $elip = 0.0 ; # ellipticity in 45 degree sense $radius = 0.275 ; # was .28 $shelf = 0.1 ; # how far before the dots die out $eshelf = 0.13 ; # was .3 $xmax = 580 ; # clip size $ymax = 670 ; # clip size $maxpbm = 3 ; # eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; # $period = $pbmx ; $pbmx = $repeat * $pbmx ; $pbmy = $pbmx ; $pbmfile .= $c.".pbm" ; $P = $pbmx * $pbmy ; $centrex = $pbmx * $xoff ; $centrey = $pbmy * $yoff ; $radius *= $pbmx ; $radius *= $radius ; $re *= $pbmx ; $re *= $re ; $ex = $pbmx * $ex ; $ey = $pbmy * $ey ; $pbmx = $xmax ; $pbmy = $ymax ; $stripe3start = 0 ; $stripe4start = 0 ; $stripe5start = 0 ; if ( $ascii ) { print "$pbmx $pbmy\n" ; } if ( $pbmplot ) { # note I actually write a pgm file . open (PBM,"> $pbmfile"); if ( $all > 1 ) { print PBM "P2\n# CREATOR: tartan.p DJCM 99 05\n" ; print PBM "$pbmx $pbmy\n" ; print PBM "$maxpbm\n" ; $low = 3 ; $high = 0 ; } else { print PBM "P1\n# CREATOR: tartan.p DJCM 99 05\n" ; print PBM "$pbmx $pbmy\n" ; } } for ( $i = 1 ; $i <= $P ; $i ++ ) { $c[$i] = $low ; } do { # ... while ( $c <= $all ) ; if ( $c == 2 ) { # this comes up as black-gray color in pbm.(blue) if ($spacious==2) { # narrower stripes $stripe1start = 89 ; $stripe1width = 38 ; # $stripe2start = 140 ; # $stripe1start = 90 ; # $stripe1width = 38 ; # # $stripe2start = 139 ; } else { $stripe1start = 89 ; $stripe1width = 39 ; # $stripe2start = 139 ; } $stripe2width = $stripe1width ; $lwidth = 12 ; $onwidth = 4 ; $o0 = 0 ; $oh = 7 ; $stripe3start =0; } elsif ( $c == 1 ) { $stripe3width = 7 ; $stripe3start = 268 ; if ( $spacious ) { $stripe1start = 42 ; $stripe1width = 38 ; $stripe2start = 187 ; } else { $stripe1start = 42 ; $stripe1width = 39 ; $stripe2start = 186 ; } $stripe2width = $stripe1width ; # 14 $lwidth = 12 ; # period (was 6 and 2) (or 8 and 3) $onwidth = 4 ; # amount of ink $o0 = 0 ; $oh = 7 ; } elsif ( $c == 3 ) { $stripe3start = 130 ; $stripe3width = 7 ; $stripe4start = 180 ; $stripe4width = 4 ; if ($spacious) { $stripe5start = 228 ; $stripe5width = 37 ; $stripe1start = 2 ; $stripe1width = 37 ; } else { $stripe5start = 227 ; $stripe5width = 39 ; $stripe1start = 1 ; $stripe1width = 39 ; } $stripe2start = 83 ; $stripe2width = 4 ; $lwidth = 12 ; # period (was 6 and 2) (or 8 and 3) $onwidth = 4 ; # amount of ink $o0 = 0 ; $oh = 7 ; } $stripe1end = $stripe1start + $stripe1width ; $stripe2end = $stripe2start + $stripe2width ; $off = 0 ; for ( $t = $stripe1start ; $t <= $stripe1end ; $t ++ ) { &doit() ; } $off = 0 ; for ( $t = $stripe2start ; $t <= $stripe2end ; $t ++ ) { &doit() ; } if ( $stripe3start ) { $stripe3end = $stripe3start + $stripe3width ; $off = 0 ; for ( $t = $stripe3start ; $t <= $stripe3end ; $t ++ ) { &doit() ; } } if ( $stripe4start ) { $stripe4end = $stripe4start + $stripe4width ; $off = 0 ; for ( $t = $stripe4start ; $t <= $stripe4end ; $t ++ ) { &doit() ; } } if ( $stripe5start ) { $stripe5end = $stripe5start + $stripe5width ; $off = 0 ; for ( $t = $stripe5start ; $t <= $stripe5end ; $t ++ ) { &doit() ; } } &markers ; $c ++ ; $high ++ ; # assumes high was 1... } while ( $c <= $all ) ; sub markers { docross ( $pbmx - 30 , $pbmy - 80 , $c * 5 -4 , ($c+1)* 5 - 5 ) ; docross ( 30 , 130 , $c * 5 -4 , ($c+1)* 5 - 5 ) ; } sub docross { local ( $xx , $yy , $start , $end ) = @_ ; $y = $yy ; for ( $x = $xx - $end ; $x <= $xx - $start ; $x ++ ) { $i0 = $x + ($y-1) * $pbmx ; $c[$i0] = $high; } for ( $x = $xx + $start ; $x <= $xx + $end ; $x ++ ) { $i0 = $x + ($y-1) * $pbmx ; $c[$i0] = $high; } $x = $xx ; for ( $y = $yy - $end ; $y <= $yy - $start ; $y ++ ) { $i0 = $x + ($y-1) * $pbmx ; $c[$i0] = $high; } for ( $y = $yy + $start ; $y <= $yy + $end ; $y ++ ) { $i0 = $x + ($y-1) * $pbmx ; $c[$i0] = $high; } } sub checkdraw { # local ($x,$y) = @_ ; # $x -= $dx ; # $y -= $dy ; return if ( $x > $pbmx || $y > $pbmy ); if ( $circle ) { $rc = ($x-$centrex)**2 + ($y-$centrey)**2 ; if ( $rc > $radius ) { $p = 1.0 - ( $rc/$radius - 1.0 ) / $shelf ; if ( $p <= 0.0 || rand() > $p ) { return ; } } } if ( $circle2 ) { $rc = ($x-$ex)**2*$efx + ($y-$ey)**2 + $elip * ($y-$ey) * ($x-$ex) ; if ( $rc < $re ) { $p = 1.0 - ( 1.0 - $rc/$re ) / $eshelf ; if ( $p <= 0.0 || rand() > $p ) { return ; } } } $i0 = $x + ($y-1) * $pbmx ; $c[$i0] = $high; } # # # 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" ; sub dorepeat { $x += $period ; &checkdraw ; $y += $period ; &checkdraw ; $x -= $period ; &checkdraw ; if ( $repeat > 2 ) { $y += $period ; &checkdraw ; $x += $period ; &checkdraw ; $x += $period ; &checkdraw ; $y -= $period ; &checkdraw ; $y -= $period ; &checkdraw ; } } sub doit { # off is the offset for the very first stripe $off = ($t+$o0) % $lwidth + 1 ; # off2 is the offset in the current stripe, which rotates. $off2 = $off ; $off3 = $off + $oh ; for ( $s = 1 ; $s <= $period ; $s ++ ) { if ( $off2 >= $lwidth ) { $off2 -= $lwidth ; } if ( $off3 >= $lwidth ) { $off3 -= $lwidth ; } if ( $off3 < $onwidth ) { $x = $period+1-$t ; $y = $period+1-$s ; &checkdraw ; if ( $repeat ) { &dorepeat ; } } if ( $off2 < $onwidth ) { $x = $s ; $y = $t ; &checkdraw ; if ( $repeat ) { &dorepeat ; } } # $off2 ++ ; $off3 ++ ; } }