1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#!@xtk04_LOCATION@ -f
# -*-tcl-*-
# $Id: tk04.in 11657 2011-03-19 21:57:18Z airwin $
# Maurice LeBrun
# 30 Jun 1994
#
# @> A script illustrating use of 2-d tcl api (plframe).
###############################################################################
package require Itk
wm title . "tk04"
plstdwin .
###############################################################################
# Set up the menubar and message widgets.
frame .menu -relief raised -borderwidth 3
button .menu.comp -text "Compute Function" -command "compute"
button .menu.contour -text "Line Contour" -command "contour"
button .menu.shade -text "Color Fill Contour" -command "shade"
pack .menu.comp .menu.contour .menu.shade -side left
button .menu.exit -text "Exit" -command "destroy ."
pack .menu.exit -side right
message .msg \
-font -Adobe-helvetica-medium-r-normal--*-240* -aspect 200 \
-width 500 -borderwidth 1 \
-text "TK04: 2-d Tcl API"
pack .menu .msg -fill x
tk_menuBar .menu .menu.comp .menu.contour .menu.shade .menu.exit
PLXWin .plw
pack .plw -side bottom -expand 1 -fill both
matrix x f 64 64
# This is the front end to the data computation. Initially we just
# create the matrix to hold the data, and then vector down to the C
# side to set the data. However, one could easily embellish this to
# accept specifications from the user (via Tk entries), and act on
# them. For instance, choosing the size of the matrix, passing
# paramaters to the compiled side, etc.
proc compute {} {
global x
get_data x
}
# Draw a contour of the data.
proc contour {} {
global x
.plw pladv
.plw plvpor 0.1 0.9 0.1 0.9
.plw plwind 1. 64. 1. 64.
.plw plcol0 6
.plw pllab "(x)" "(y)" "#frPLplot Example Tk04"
# plot the data points
.plw plcol0 9
matrix clev f 10
set max [x max]
set min [x min]
for {set i 0} {$i < 10} {incr i} {
clev $i = [expr $min + ($max-$min)*($i+.5)/10 ]
}
.plw plcont x clev
.plw plcol0 1
.plw plbox "bcnst" 0.0 0 "bcnstv" 0.0 0
}
proc shade {} {
global x
.plw pladv
.plw plvpor 0.1 0.9 0.1 0.9
.plw plwind 0. 1. 0. 1.
.plw plcol0 6
.plw pllab "(x)" "(y)" "Cool shade plot example from Tcl"
set max [x max]
set min [x min]
set xmin 0
set xmax 1
set ymin 0
set ymax 1
for {set i 0} {$i < 20} {incr i} {
set sh_min [expr $min + ($max-$min)*$i/20.]
set sh_max [expr $min + ($max-$min)*($i+1)/20.]
set sh_col [expr $i/20.]
.plw plshade x $xmin $xmax $ymin $ymax $sh_min $sh_max 1 $sh_col 0 \
1 0 0 0 \
1 "NULL"
}
.plw plcol0 1
.plw plbox "bcnst" 0.0 0 "bcnstv" 0.0 0
}
###############################################################################
|