From: Rich Date: 2004-06-19T13:23:07+09:00 Subject: Re: Generating "real-time" 2D line plots in Windows 2k? ----- Original Message ----- From: "Todd Gardner" Newsgroups: comp.lang.ruby To: "ruby-talk ML" Sent: Friday, June 18, 2004 7:23 PM Subject: Re: Generating "real-time" 2D line plots in Windows 2k? > I first must apologize. I am using the voice dictation software Don't worry. > Dragon NaturallySpeaking are Windows 2000 and it sometimes gets things > correct however, sometimes when it messes up messes up big-time and I > just don't notice all of the completely erroneous words. > lol - I mess up and I'm typing!! > I am unable to access http://lithinos.com/ so the subsequent link does > not work. > Yeah - it's not the greatest hosting company... lots of downtime. > I had downloaded fox-1.2.4 but I am unsure how to use it with Windows. > Would you mind getting this newbie pointers so that I can get this > installed properly? > I wouldn't do it that way. I'd get the one-click installer - it has everything you'll need for FOX and FXRuby. The one-click installer is at: http://rubyforge.org/frs/?group_id=167 Download that, and run it to get everything setup. After you have that going, just save the following code into a file (".rb") and double-click it. START CODE require 'fox' include Fox @appRef=FXApp.new @mainwin=FXMainWindow.new(@appRef,"Moving Graph",nil,nil,LAYOUT_FIX_HEIGHT|LAYOUT_FIX_WIDTH|DECOR_ALL) @mainwin.x=@mainwin.y=200 @mainwin.width=300 @mainwin.height=300 def paint(n,l,d) if(@first.nil?) @repaint_n=n @repaint_l=l @repaint_d=d end FXDCWindow.new(@canvas, d) do |dc| dc.foreground = @canvas.backColor dc.fillRectangle(d.rect.x, d.rect.y, d.rect.w, d.rect.h) end end def clear_canvas FXDCWindow.new(@canvas) do |dc| dc.foreground = @canvas.backColor dc.fillRectangle(0, 0, @canvas.width, @canvas.height) end end def draw_graph clear_canvas FXDCWindow.new(@canvas) do |dc| dc.foreground=FXRGB(115,0,0) x=0 @points.each{|i| h=@canvas.height dc.drawLine(x,h,x,h-i) x+=1 } end end def create_next_value(n,l,d) if(!@firstTime.nil?) 1.times do @show_next_value.text=@points.last.to_s sleep(1) @points.shift l=@points.last if(rand(10)>=5) new_value=l+rand(10) new_value=200 if new_value>200 new_value=25 if new_value<0 @points << new_value else new_value=l-rand(10) new_value=200 if new_value>200 new_value=25 if new_value<0 @points << new_value end end else @firstTime=true (@canvas.width-2).times do |i| l=@points.last if(rand(10)>=5) new_value=l+rand(10) new_value=200 if new_value>200 new_value=25 if new_value<0 @points << new_value else new_value=l-rand(10) new_value=200 if new_value>200 new_value=25 if new_value<0 @points << new_value end end end draw_graph @appRef.addTimeout(1, method(:create_next_value)) end @show_next_value=FXTextField.new(@mainwin,20,nil,0,LAYOUT_FILL_X|TEXTFIELD_N ORMAL) @canvas=FXCanvas.new(@mainwin,nil,0,FRAME_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y ) @canvas.connect(SEL_PAINT,method(:paint)) @points=[100] @appRef.addTimeout(1, method(:create_next_value)) @appRef.create @mainwin.show(PLACEMENT_SCREEN) @appRef.run END CODE That's just an example that I whipped up for you. You'll probably want to do a bit more with your GUI. > Also, I would really appreciate it if you show me how to build that > example to an executable. > After we get the above stuff working, I'd be happy to walk you through it - it's super easy. Remember though - you're not really 'building' it into an executable... you're packaging the Ruby source file with the Ruby interpreter and FOX library, and distributing everything in a single file with an EXE extension that can be double-clicked to run. It will look and function the same as a 'compiled' or 'built' EXE, but it isn't really... > Any ideas would be greatly appreciated, > > Thank you, > > Todd > Not a problem! -Richard