Version 1 of BLT - stripchart - with realtime update

Updated 2007-01-03 19:05:44 by LV

# realtime stripchart 200 Hz

 package require Tk
 package require BLT
 namespace import blt::*

 # vector and stripchart are blt components.
 # if you have a vector v, you can update it in realtime with
 # v set $list

 # init the vector to a fixed size.

 vector xvec y1vec y2vec

 set xlist {}
 set y1list {}
 set y2list {}

 for {set i 0} {$i < 200} {incr i} {
        lappend xlist $i
        lappend y1list 0
        lappend y2list 0
 }

 xvec set $xlist
 y1vec set $y1list
 y2vec set $y2list

 stripchart .s1 -height 2i -width 8i
 stripchart .s2 -height 2i -width 8i

 pack .s1 .s2

 .s1 element create line1 -xdata xvec -ydata y1vec -pixels 1
 .s2 element create line2 -xdata xvec -ydata y2vec -pixels 2 -color red

 # update 200 Hz random data once per second

 proc proc1sec {} {
        set y1list {}
        set y2list {}
        for {set i 0} {$i < 200} {incr i} {
                lappend y1list [expr {rand()}]
                lappend y2list [expr {rand()}]
        }
        y1vec set $y1list
        y2vec set $y2list

        after 1000 proc1sec
 }

 proc1sec

Andrew Tannenbaum


Category Plotting