(buggy) iris animation

FF - 2007-07-19 - I wanted to try (another) iris animation -I don't know how to explain that, better you try it yourself- but after writing the code and seeing the program running I realized there was a little problem... canvas objects should have be arranged in a manner like the Escher's Infinite Staircase

http://www.sirgalahad.org/paul/sw/winlock/img/stairs-small.png

in respect to the canvas z-ordering system...

I don't know how to fix that, so enjoy it with the little bug ;-)

P.S. it makes use of the Canvas Rotation by Keith Vetter


AMG: You might have to manually clip your polygons against each other.


 proc RotateItem {w tagOrId Ox Oy angle} {
    set angle [expr {$angle * atan(1) * 4 / 180.0}] ;# Radians
    foreach id [$w find withtag $tagOrId] {     ;# Do each component separately
        set xy {}
        foreach {x y} [$w coords $id] {
            # rotates vector (Ox,Oy)->(x,y) by angle clockwise

            set x [expr {$x - $Ox}]             ;# Shift to origin
            set y [expr {$y - $Oy}]

            set xx [expr {$x * cos($angle) - $y * sin($angle)}] ;# Rotate
            set yy [expr {$x * sin($angle) + $y * cos($angle)}]

            set xx [expr {$xx + $Ox}]           ;# Shift back
            set yy [expr {$yy + $Oy}]
            lappend xy $xx $yy
        }
        $w coords $id $xy
    }
 }

 set W 800
 set H 600
 set nitems 12
 set Ox [expr $W/2]
 set Oy [expr $H/2]

 proc Main {} {
    pack [canvas .c -width $::W -height $::H]
    for {set i 0} {$i < $::nitems} {incr i} {
        .c create poly {500 -250 1600 -250 1600 1400 500 1400} \
            -fill red -outline black -tag item$i
        RotateItem .c item$i $::Ox $::Oy -[expr 360.*$i/$::nitems]
    }
 }

 proc Step {} {
    set radius 200
    for {set i 0} {$i < $::nitems} {incr i} {
        set Ox1 [expr $::Ox+$radius*sin(3.14159*2.*$i/$::nitems)]
        set Oy1 [expr $::Oy+$radius*cos(3.14159*2.*$i/$::nitems)]
        RotateItem .c item$i $Ox1 $Oy1 3
    }
    after 50 Step
 }

 Main
 after 50 Step