Posted to tcl by daapp at Thu Jan 22 09:40:59 GMT 2009view raw

  1. package require Tk
  2. package require BLT
  3. namespace import blt::*
  4.  
  5. # vector and stripchart are blt components.
  6. # if you have a vector v, you can update it in realtime with
  7. # v set $list
  8.  
  9. # init the vectors to a fixed size.
  10.  
  11. set Hz 400
  12.  
  13. vector xvec($Hz) y1vec($Hz) y2vec($Hz)
  14.  
  15. # fill xvec with 0 .. $Hz-1
  16.  
  17. xvec seq 0 [expr {$Hz - 1}]
  18.  
  19. stripchart .s1;# -height 2i -width 8i -bufferelements yes
  20.  
  21. pack .s1 -fill both -expand true
  22.  
  23. .s1 element create line1 -xdata xvec -ydata y1vec -symbol none
  24.  
  25. # update $Hz values with random data once per second
  26.  
  27.  
  28. Blt_ZoomStack .s1
  29. Blt_Crosshairs .s1
  30. Blt_ActiveLegend .s1
  31. Blt_ClosestPoint .s1
  32.  
  33.  
  34. set i 0
  35. proc proc1sec {} {
  36.  
  37. # this can be done more concisely with vector random,
  38. # but if you need to fill a vector from scalar calculations,
  39. # do it this way:
  40. global i y1list y2list
  41.  
  42.  
  43. if {$i < $::Hz} {
  44. lappend y1list [expr {rand() * 100}]
  45. incr i
  46. y1vec set $y1list
  47. after 1 proc1sec
  48. }
  49.  
  50. }
  51.  
  52. proc1sec
  53. focus -force .
  54.