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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
#!@xtk02_LOCATION@ -f
# -*-tcl-*-
# Geoffrey Furnish
# 11 April 1994
#
# @> A script for using Tk to control xtk02, using the PLplot itcl interface.
###############################################################################
package require Pltk
eval package require $pl_itk_package_name
wm title . "x01c -- Tk/Itcl version"
plstdwin .
###############################################################################
# Set up the menubar and message widgets.
frame .menu -relief raised -borderwidth 3
button .menu.one -text "One" -command "myplot1"
pack append .menu .menu.one {left expand fill}
button .menu.two -text "Two" -command "myplot 2"
pack append .menu .menu.two {left expand fill}
button .menu.three -text "Three" -command "plot2"
pack append .menu .menu.three {left expand fill}
button .menu.four -text "Four" -command "myplot 4"
pack append .menu .menu.four {left expand fill}
button .menu.five -text "Five" -command "gumbyplot"
pack append .menu .menu.five {left expand fill}
button .menu.six -text "Six" -command "snoopy"
pack .menu.six -side left -expand 1 -fill x
button .menu.exit -text "Exit" -command "quit 0"
pack append .menu .menu.exit {right expand fill}
message .msg \
-font -Adobe-helvetica-medium-r-normal--*-240* -aspect 200 \
-width 500 -borderwidth 1 \
-text "TK02: Demo \[incr Tcl\] interface to PLplot"
#PLXWin .plw
Pltkwin .plw
pack append . .menu {top fillx} \
.msg {top padx 5 pady 5 fill} \
.plw {bottom expand fill}
update
tk_menuBar .menu .menu.one .menu.two .menu.three .menu.four .menu.exit
###############################################################################
# Definitions of procedures used in this script.
proc myplot1 {} {
global xscale yscale xoff yoff
set xscale 6
set yscale 1
set xoff 0
set yoff 0
plot1
}
# This is supposed to work just like the plot1() in x01c.c/xtk02.c
proc plot1 {} {
global xscale yscale xoff yoff
matrix x1 float 10
matrix y1 float 10
for {set i 2; set n1 0} {$i < 60} {incr i 10; incr n1} {
set x [expr $xoff + $xscale * ($i + 1) / 60]
x1 $n1 = $x
y1 $n1 = [expr $yoff + $yscale * pow($x,2)]
}
set n2 60
matrix x2 float $n2
matrix y2 float $n2
for {set i 0} {$i < $n2} {incr i} {
set x [expr $xoff + $xscale * ($i + 1) / $n2]
x2 $i = $x
y2 $i = [expr $yoff + $yscale * pow($x,2)]
}
set xmax [x2 [expr $n2-1]]
set ymax [y2 [expr $n2-1]]
.plw plcol0 1
.plw plenv $xoff $xmax $yoff $ymax 0 0
.plw plcol0 6
.plw pllab "(x)" "(y)" "#frPLPLOT Example 1 - y=x#u2"
# plot the data points
.plw plcol0 9
matrix xplot f $n1 = [x1 :]
matrix yplot f $n1 = [y1 :]
.plw plpoin xplot yplot 9
# plot the data points
.plw plcol0 4
.plw plline x2 y2
}
# This is supposed to work just like the plot2() in x01c.c/xtk02.c
proc plot2 {} {
.plw plcol0 1
.plw plenv -2 10 -.4 1.2 0 1
.plw plcol0 2
.plw pllab "(x)" "sin(x)/x" "#frPLPLOT Example 1 - Sinc Function"
# Fill up the array
matrix x1 float 101
matrix y1 float 101
for {set i 0} {$i < 101} {incr i} {
set x [expr ($i - 19.)/6.]
x1 $i = $x
y1 $i = 1
if {$x != 0} { y1 $i = [expr sin($x)/$x] }
}
.plw plcol0 3
.plw plline x1 y1
}
proc gumbyplot {} {
.plw plcol0 1
.plw plenv 0 1 0 1 0 0
.plw plcol0 6
.plw pllab "(x)" "(y)" "#frPLplot Example 1 - y=1-2x+2x#u2"
matrix x1 float 101
matrix y1 float 101
for {set i 0} {$i < 101} {incr i} {
set x [expr $i * .01]
x1 $i = $x
y1 $i = [expr 1 - 2 * $x + 2 * $x * $x]
}
.plw plline x1 y1
}
# This proc shows off the use of a matrix extension subcommand.
proc snoopy {} {
matrix x float 101
matrix y float 101
for {set i 0} {$i < 101} {incr i} {
set xx [expr $i * .01]
x $i = $xx
}
y stuff
.plw plcol0 1
.plw plenv 0 1 0 1 0 0
.plw plcol0 6
.plw pllab "(x)" "(y)" "#frDemo of Matrix extension subcommand"
.plw plline x y
}
# Punch eject and hold onto your seat !!!
proc quit a {
exit
}
# Utility routine.
proc dpos w {
wm geometry $w +300+300
}
###############################################################################
|