#!xtk04 -f
# Maurice LeBrun                     -*-tcl-*-
# 30 Jun 1994
#
# @> A script illustrating use of 2-d tcl api (plframe).
#
# $Id: tk04,v 1.5 1996/10/18 20:00:35 furnish Exp $
#
# $Log: tk04,v $
# Revision 1.5  1996/10/18  20:00:35  furnish
# Use "package require" so that these fail in a reasonable way if
# itcl/itk not configured.  Prior behavior was uninteligible.  This way
# the package mechanism is used the way it is supposed to be used.  At
# least if it fails, people will be able to understand why.
#
# Revision 1.4  1995/07/04  21:51:46  furnish
# Corrected to reflect the new syntax of the plshade call.
#
# Revision 1.3  1995/06/09  22:49:52  mjl
# Switched from plenv to plvpor/plwind/plbox in order to avoid overwriting
# tick marks by judicious placement of the plbox call.
#
# Revision 1.2  1994/10/10  19:45:02  furnish
# Imlemented plshade from Tcl.
#
# Revision 1.1  1994/10/10  17:23:50  furnish
# Tk script to show off new 2-d plframe API.
#
###############################################################################

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 plcol 6
    .plw pllab "(x)" "(y)" "#frPLplot Example Tk04"

    # plot the data points

    .plw plcol 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 plcol 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 plcol 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
	    
    }

    .plw plcol 1
    .plw plbox "bcnst" 0.0 0 "bcnstv" 0.0 0
}

###############################################################################
