Artifact a2d596583956d29fc1e5280036926b9075ea00903ae6dc396969380c4d08498f:
package require Tk
label .l -text "Use a and s to rotate"
grid .l -row 0 -column 0 -sticky ew
canvas .c -width 300 -height 300 -bg white
grid .c -row 1 -column 0
entry .e
grid .e -row 2 -column 0 -sticky ew
bind .c <Button-1> {focus .c}
set nodes1 {150 175 125 25 175 25}
set nodes2 {150 125 125 275 175 275}
set blade1 [.c create polygon $nodes1 -fill red -smooth bezier]
set blade2 [.c create polygon $nodes2 -fill red -smooth bezier]
set hub [.c create oval 125 125 175 175 -fill blue]
proc rotatePoint {p angle} {
set x [lindex $p 0]
set y [lindex $p 1]
set dx [expr $x - 150]
set dy [expr $y - 150]
set c [::tcl::mathfunc::cos $angle]
set s [::tcl::mathfunc::sin $angle]
return [list [expr 150 + $c * $dx + $s * $dy] \
[expr 150 - $s * $dx + $c * $dy]]
}
proc rotateCoords {coords angle} {
set result {}
for {set i 0} {$i < [llength $coords]} {incr i} {
set p [list [lindex $coords $i] [lindex $coords [incr i]]]
set result [concat $result [rotatePoint $p $angle]]
}
return $result
}
proc rotate {angle} {
global blade1 nodes1 blade2 nodes2
set nodes1 [rotateCoords $nodes1 $angle]
set nodes2 [rotateCoords $nodes2 $angle]
.c coords $blade1 $nodes1
.c coords $blade2 $nodes2
}
proc animate {} {
global rotationAngle
while {1} {
set done 0
after 33 set done 1
if {$rotationAngle != 0} {rotate $rotationAngle}
vwait done
}
}
set rotationAngle 0
bind . <Destroy> {exit}
bind .c <KeyPress-a> {set rotationAngle 0.05}
bind .c <KeyPress-s> {set rotationAngle -0.05}
bind .c <KeyRelease> {set rotationAngle 0}
animate
