require 'tkmove4.rb' include TestBed def get_item_coords( item ) coord = item.coords coord_array = [] x = coord.shift y = coord.shift while x != nil coord_array.push( [x.to_f, y.to_f] ) x = coord.shift y = coord.shift end coord_array end def min_max( coord_array, index ) temp = coord_array.collect{|c| c[index]} [ temp.min, temp.max ] end def mirror( item, index ) coords_array = get_item_coords( item ) min, max = min_max( coords_array, index) axis = ( min + max ) temp = coords_array.collect{|c| c[index] = axis - c[index]; c } eval "item.coords( #{temp.join(',')} )" end def mirror_at_cursor( canvas, index ) item = canvas.find_withtag('current').shift mirror( item, index ) end c = TkCanvas.new.pack testbed(c) TkButton.new(nil, 'text'=>'mirror', 'command'=>proc{ TkRoot.new.cursor('hand2') c.bind('1', proc{}) c.bind('B1-Motion', proc{}) c.itembind('item', '1', proc{ mirror_at_cursor( c, 0 ) }) }).pack Tk.mainloop