#!xtk04 -f
# Maurice LeBrun                     -*-tcl-*-
# 30 Jun 1994
#
# @> A script illustrating use of 2-d tcl api (plframe).
#
# $Id: tk04,v 1.2 1994/10/10 19:45:02 furnish Exp $
#
# $Log: tk04,v $
# 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.
#
###############################################################################

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 plcol 1
#    .plw plenv 0 1 0 1 0 0
    .plw plenv 1 64 1 64 0 0
    .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]

    #puts "max = $max, min = $min"

    for {set i 0} {$i < 10} {incr i} {
	clev $i = [expr $min + ($max-$min)*($i+.5)/10 ]
    }

    .plw plcont x clev
}

proc shade {} {
    
    global x
    .plw plcol 1
    .plw plenv 0 1 0 1 0 0
    .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 $sh_col
    }
}

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