From: Hidetoshi NAGAI Date: 2005-11-14T00:59:19+09:00 Subject: Re: Scheudle display From: "csjasnoch@wisc.edu" Subject: Re: Scheudle display Date: Fri, 11 Nov 2005 06:22:14 +0900 Message-ID: <1131657574.017316.243080@o13g2000cwo.googlegroups.com> > Example: > > Someone wants a schedule that is trigger on at 00:00 and off at 6:00 > then on again at 12:00 then off again at 18:00. > > Each time they add these seperate events to the schedule a the canvas > needs to adjusst its picutre accordingly. With this example in the end > it would be divided evenly into 4 sections 0degrees to 90degrees would > be red (or whatever color), as well as 180 to 270 degrees. The > remaining sections would remain white (or whatever color is > initialized). Hmm... How about the following? ------------------------------------------------------------------------- require 'tk' class Sched24 def initialize @c = TkCanvas.new(:width=>400, :height=>400, :scrollregion=>[-200, -200, 200, 200] ).pack(:fill=>:both, :expand=>true) @tag = TkcTag.new(@c) @circle_coords = [[-180, -180], [180, 180]] @oval = TkcOval.new(@c, @circle_coords, :fill=>'white', :tags=>[@tag]) @center_dot = TkcOval.new(@c, [-5, -5], [5, 5], :fill=>'black') @l = TkLabel.new(:text=>'00:00').pack cmd = proc{|x, y| @l.text = '%02d:%02d' % coords_to_time(@c.canvasx(x), @c.canvasy(y)) } @c.bind('Motion', cmd, '%x %y') @tag.bind('Motion', cmd, '%x %y') end def coords_to_time(x, y) return ((y < 0)? [0, 0]: [12, 0]) if x == 0 h, m = (720.0*Math.atan2(y,x)/Math::PI).divmod(60) hh = (x<0 && y<0)? h+30:h+6 mm = m.round if mm >= 60 hh += 1 mm -= 60 end [hh, mm] end def create_pie(hh, mm, span, color='red') start = 90.0 - (hh*60 + mm)/4.0 # 360.0*(hh*60+mm)/(24*60) extent = -span/4.0 pie = TkcArc.new(@c, @circle_coords, :tags=>[@tag], :outline=>'black', 'fill'=>color, :start=>start, :extent=>extent) @center_dot.raise pie end end sched = Sched24.new sched.create_pie(0,0, 60) # 60 minutes from 00:00 sched.create_pie(6,30, 280, 'green') # 280 minutes from 06:30 sched.create_pie(15,20, 90, 'blue') # 90 minutes from 15:20 Tk.mainloop ------------------------------------------------------------------------- -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)