Rev | Line | |
---|
[175] | 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 200
|
---|
| 12 |
|
---|
| 13 | vector xvec($Hz) y1vec($Hz) y2vec($Hz) sx1($Hz) sy1($Hz)
|
---|
| 14 |
|
---|
| 15 | # fill xvec with 0 .. $Hz-1
|
---|
| 16 |
|
---|
| 17 | xvec seq 0 [expr {$Hz - 1}]
|
---|
| 18 | #xvec populate sx1 $Hz
|
---|
| 19 | sx1 seq 0 [expr {$Hz - 1}]
|
---|
| 20 |
|
---|
| 21 | stripchart .s1 -height 2i -width 8i -bufferelements no
|
---|
| 22 | stripchart .s2 -height 2i -width 8i -bufferelements no
|
---|
| 23 |
|
---|
| 24 | pack .s1 .s2
|
---|
| 25 |
|
---|
| 26 | .s1 element create line1 -xdata xvec -ydata y1vec -symbol none
|
---|
| 27 | .s2 element create spline -x sx1 -y sy1 -symbol none -color red
|
---|
| 28 |
|
---|
| 29 | #.s2 element create line2 -xdata xvec -ydata y2vec -symbol none -color red
|
---|
| 30 |
|
---|
| 31 | # update $Hz values with random data once per second
|
---|
| 32 |
|
---|
| 33 | proc proc1sec {} {
|
---|
| 34 |
|
---|
| 35 | # this can be done more concisely with vector random,
|
---|
| 36 | # but if you need to fill a vector from scalar calculations,
|
---|
| 37 | # do it this way:
|
---|
| 38 |
|
---|
| 39 | for {set i 0} {$i < $::Hz} {incr i} {
|
---|
| 40 | lappend y1list [expr {rand()}]
|
---|
| 41 | lappend y2list [expr {rand()}]
|
---|
| 42 | }
|
---|
| 43 | y1vec set $y1list
|
---|
| 44 | y2vec set $y2list
|
---|
| 45 |
|
---|
| 46 | spline natural xvec y1vec sx1 sy1
|
---|
| 47 |
|
---|
| 48 | after 200 proc1sec
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | proc1sec
|
---|
Note:
See
TracBrowser
for help on using the repository browser.