Version 1 of A minimal starfield

Updated 2005-05-17 17:39:24 by suchenwi

if 0 {Richard Suchenwirth 2005-05-17 - In a few leisurely minutes at work, I hacked together these 17 LOC that give you kind of a starfield animation by scaling ovals on a canvas :)

http://mini.net/files/stars.jpg }

 package require Tk
 proc stars'go {c factor ms} {
     set w [winfo width $c]
     set h [winfo height $c] 
     $c scale all [expr {$w/2.}] [expr {$h/2.}] $factor $factor 
     foreach item [$c find all] {
         foreach {x0 y0 x1 y1} [$c bbox $item] break
         if {$x1<0 || $x0>$w || $y1<0 || $y0>$h} {$c delete $item}
     }
     set x [expr {rand()*$w}]
     set y [expr {rand()*$h}]
     $c create oval $x $y [expr {$x+2}] [expr {$y+2}] -fill white
     after $ms [info level 0]
 }

#-- Let's go!

 pack [canvas .c -bg black] -fill both -expand 1
 stars'go .c 1.01 40

if 0 {


Category Animation - Arts and crafts of Tcl-Tk programming}