|
setup diary |
require 'thread' require 'tk' require 'tkextlib/blt' graph = Tk::BLT::Graph.new.pack graph.title="title" graph.axis_configure('x',:title=>'x-axis') #graph.axis_configure('x',:min=>'0',:max=>'4') #graph.axis_configure('y',:min=>'0',:max=>'4') graph.axis_configure('x',:ticklength=>5) graph.axis_configure('x',:showticks=>true) graph.gridline_on() graph.legend_configure( :hide=>'yes') graph.crosshairs_configure( :hide=>'no') graph.xaxis_bind('1', proc{|x,y| puts "x(%d,%d)"%[x,y]},"%x %y") graph.yaxis_bind('1', proc{|x,y| puts "y(%d,%d)"%[x,y]},"%x %y") xx=Tk::BLT::Vector.new() yy=Tk::BLT::Vector.new() zz=Tk::BLT::Vector.new() plot = Tk::BLT::PlotComponent::Element.new(graph, 'plot1', :label=>'foo') plot.configure( :xdata=>xx, :ydata=>yy) plot.configure( :linewidth=>1) plot.configure( :symbol=>'plus',:pixels=>5) #"none","circle", "square", "diamond", "plus", "cross", #"splus", "scross", "triangle", "arrow" plot2 = Tk::BLT::PlotComponent::Element.new(graph, 'plot2', :label=>'foo') plot2.configure( :xdata=>xx, :ydata=>zz) plot2.configure( :color=>"red") plot2.configure( :symbol=>'cross',:pixels=>5) Thread.start{ i=0 loop{ xx.append(i) yy.append(Math.sin(i*0.01) ) zz.append(Math.cos(i*0.01) ) sleep 0.2 i+=1 }} Tk.mainloopいろいろなオプションを指定すると、綺麗なグラフをオンタイムで書ける気がする。もう少しいじってみよう。