From: Hidetoshi NAGAI Date: 2005-05-06T23:41:53+09:00 Subject: Re: Ruby-tk question From: Joe Van Dyk Subject: Re: Ruby-tk question Date: Fri, 6 May 2005 14:45:18 +0900 Message-ID: > It's horribly difficult for someone who hasn't done math in years. Here is an example. :-) ----------------------------------------------- require 'tk' def rotate(deg, x, y, c_x = 0, c_y = 0) rad = (deg * Math::PI)/180.0 s_rad = Math::sin(rad) c_rad = Math::cos(rad) x -= c_x y -= c_y [c_x + (x * c_rad - y * s_rad), c_y + (x * s_rad + y * c_rad)] end coords = [[100, 100], [200, 100], [100, 140]] center = [120, 120] c = TkCanvas.new.pack poly = TkcPolygon.new(c, coords, :fill=>'red') TkcOval.new(c, center[0] - 2, center[1] - 2, center[0] + 2, center[1] + 2, :fill=>'black') deg = 0 TkTimer.start(50, -1, proc{ deg = (deg + 5) % 360 poly.coords(coords.collect{|x, y| rotate(deg, x, y, *center)}) }) Tk.mainloop ----------------------------------------------- -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)