source: trunk/kitgen/8.x/blt/function_plotting.tcl@ 193

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

initial commit

File size: 1.3 KB
Line 
1package require BLT
2namespace import ::blt::*
3
4proc compute args {
5puts $::a
6puts $::b
7puts $::c
8puts $::d
9#puts [vector expr {($::a * (::x ^ 3)) + ($::b * (::x ^ 2)) + ($::c * ::x) + $::d}]
10puts [vector expr {::x}]
11
12}
13
14label .l -text "Function: ax^3 + bx^2 + cx + d" ; table . .l 0,0
15
16graph .g -width 700 -height 600 -bd 2 -relief groove ; table . .g 1,0 -fill both
17Blt_ZoomStack .g
18
19vector ::x
20::x seq -10 10 0.5
21vector ::y
22
23set items {label variable to from digits resolution tickinterval gridpos}
24set scale_cfg {
25 a ::a -0.31 0.3 5 0.001 0.1 1,1
26 b ::b -1.01 1.0 5 0.002 0.5 1,2
27 c ::c -4.01 4.0 4 0.01 2.0 1,3
28 d ::d -10.01 10.0 3 0.1 5.0 1,4
29}
30
31foreach $items $scale_cfg {
32 set $variable 1.0
33 trace variable $variable w compute
34
35 set w .sc$label
36 set label [ string totitle $label ]
37 scale $w -label $label \
38 -variable $variable -to $to -from $from \
39 -digits $digits -resolution $resolution \
40 -tickinterval $tickinterval \
41 -bd 2 -relief groove
42 table . $w $gridpos -fill y
43}
44
45# fill vector ::y
46compute
47
48.g element create Function -xdata ::x -ydata ::y -pixels 3
49.g axis configure y -min -20 -max 20
50.g grid configure -hide no -dashes { 2 2 }
51
52# ready
Note: See TracBrowser for help on using the repository browser.