source: trunk/kitgen/8.x/blt/realtime_stripchart.tcl@ 201

Last change on this file since 201 was 175, checked in by demin, 12 years ago

initial commit

File size: 1.2 KB
Line 
1package require Tk
2package require BLT
3namespace 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
11set Hz 200
12
13vector xvec($Hz) y1vec($Hz) y2vec($Hz) sx1($Hz) sy1($Hz)
14
15# fill xvec with 0 .. $Hz-1
16
17xvec seq 0 [expr {$Hz - 1}]
18#xvec populate sx1 $Hz
19sx1 seq 0 [expr {$Hz - 1}]
20
21stripchart .s1 -height 2i -width 8i -bufferelements no
22stripchart .s2 -height 2i -width 8i -bufferelements no
23
24pack .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
33proc 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
51proc1sec
Note: See TracBrowser for help on using the repository browser.