Line | |
---|
1 | package require BLT
|
---|
2 | namespace import ::blt::*
|
---|
3 |
|
---|
4 | proc compute args {
|
---|
5 | puts $::a
|
---|
6 | puts $::b
|
---|
7 | puts $::c
|
---|
8 | puts $::d
|
---|
9 | #puts [vector expr {($::a * (::x ^ 3)) + ($::b * (::x ^ 2)) + ($::c * ::x) + $::d}]
|
---|
10 | puts [vector expr {::x}]
|
---|
11 |
|
---|
12 | }
|
---|
13 |
|
---|
14 | label .l -text "Function: ax^3 + bx^2 + cx + d" ; table . .l 0,0
|
---|
15 |
|
---|
16 | graph .g -width 700 -height 600 -bd 2 -relief groove ; table . .g 1,0 -fill both
|
---|
17 | Blt_ZoomStack .g
|
---|
18 |
|
---|
19 | vector ::x
|
---|
20 | ::x seq -10 10 0.5
|
---|
21 | vector ::y
|
---|
22 |
|
---|
23 | set items {label variable to from digits resolution tickinterval gridpos}
|
---|
24 | set 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 |
|
---|
31 | foreach $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
|
---|
46 | compute
|
---|
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.