# primetrail.tcl -- # Use prime numbers to generate a trail in a canvas # Inspired by a newspaper article. # # The idea: draw a path in small steps where the direction # and perhaps the step size depend on successive primes # # # Four types: # 0 - Based on mod 6: the path turns left or right, depending on p%6 # 1 - Based on mod 5: the path goes north, west, south or east, based on p%5 # 2 - Based on mod 5: the path turns over 0, 90, 180 or 270 degrees # 3 - Based on mod 4: as mod 6 # set type 0 package require math::numtheory pack [canvas .c -width 800 -height 800] set x 250 set y 250 set dirx 1 set diry 0 .c create oval 245 245 255 255 -fill red if { $type == 0 || $type == 3 } { set np 5 set mod [expr {$type == 0? 6 : 4 }] } else { set np 7 } set p $np for {set i 0} {$i < 50000} {incr i} { if { $type == 0 || $type == 3 } { if { $p%$mod == 1 } { set ndirx [expr {$diry}] set ndiry [expr {-$dirx}] } else { set ndirx [expr {-$diry}] set ndiry [expr {$dirx}] } } elseif { $type == 1 } { switch -- [expr {$p%5}] { "1" { set ndirx 0; set ndiry -1 } "2" { set ndirx -1; set ndiry 0 } "3" { set ndirx 0; set ndiry 1 } "4" { set ndirx 1; set ndiry 0 } } } else { switch -- [expr {$p%5}] { "1" { set ndirx $ndirx; set ndiry $ndiry } "2" { set ndirx [expr {-$diry}]; set ndiry $dirx } "3" { set ndirx [expr {-$dirx}]; set ndiry [expr {-$diry}] } "4" { set ndirx $diry; set ndiry [expr {-$dirx}] } } } set np [expr {$np%6 == 1? $np+4 : $np+2}] set dirx $ndirx set diry $ndiry set nx [expr {$x + $dirx * 3}] set ny [expr {$y + $diry * 3}] # # Note: you could use the prime to scale the step, but then # the path quickly runs wild. # .c create line $x $y $nx $ny set x $nx set y $ny while { ! [::math::numtheory::isprime $np] } { set np [expr {$np%6 == 1? $np+4 : $np+2}] } set p $np } if { $type == 0 } { .c move all 200 400 ;# Centre it, more or less } if { $type == 2 } { .c move all 200 200 ;# Centre it, more or less }

gold added pix, random? looks like coasts of United Kingdom and Ireland