From: Ed Redman <redman / accesswave.ca>
Subject: tcl/tk translate
Date: Wed, 14 Sep 2005 10:56:33 +0900
Message-ID: <pan.2005.09.14.01.51.35.820289 / accesswave.ca>
> proc poly'rotate {w item angle} {
>     set delta [expr {$angle/180.*acos(-1)}]
>     foreach {x y} [$w coords $item] {
>         set r [expr {hypot($y,$x)}]
>         set a [expr {atan2($y,$x)+$delta}]
>         lappend coords [expr {cos($a)*$r}] [expr {sin($a)*$r}]

For example, 
---------------------------------------------------------------
require 'tk'
require 'enumerator'

def poly_rotate(citem, angle)
  delta = (angle * Math::PI)/180.0
  citem.coords = citem.coords.enum_slice(2).collect{|x, y|
    r = Math::hypot(y, x)
    a = Math::atan2(y, x) + delta
    [Math::cos(a) * r, Math::sin(a) * r]
  }
end

coords = [[100, 30], [200, 30], [100, 80]]

c = TkCanvas.new(:height=>480, :width=>480, 
                 :scrollregion=>[-240, -240, 240, 240]).pack
poly = TkcPolygon.new(c, coords, :fill=>'red')
p poly.coords

TkcOval.new(c, [[-2, -2], [2, 2]], :fill=>'black')

TkTimer.start(20, -1, proc{poly_rotate(poly, 5)})

Tk.mainloop
---------------------------------------------------------------
-- 
Hidetoshi NAGAI (nagai / ai.kyutech.ac.jp)