#!/users/mgd/packages/swarm/blt2.3/bin/bltwish
#!../bltwish

source bltDemo.tcl

set graph .graph

bitmap define pattern1 { {4 4} {01 02 04 08} }
bitmap define pattern5 { {4 4} {01 01 01 01} }

set visual [winfo screenvisual .]
if { $visual != "staticgray" && $visual != "grayscale" } {
    option add *Button.Background	red
    option add *TextMarker.Foreground	black
    option add *TextMarker.Background	yellow
    option add *LineMarker.Foreground	black
    option add *LineMarker.Background	yellow
    option add *PolyMarker.Fill		yellow2
    option add *PolyMarker.Outline	""
    option add *PolyMarker.Stipple	pattern5
    option add *activeLine.Color	red4
    option add *activeLine.Fill		red2
    option add *Element.Color		purple
}

option add *HighlightThickness		0

option add *Tile			bgTexture
option add *Button.Tile			""

image create photo bgTexture -file bitmaps/chalk.gif

frame .frame
htext .frame.msg -tileoffset no -text \
{You can zoom in on a region by clicking the left button, 
moving the pointer, and clicking again.  To restore the 
last view, click on the right button.  
Hit the %%
	button $htext(widget).quit -text {Quit} -command {exit} 
	$htext(widget) append $htext(widget).quit
%% button when you've seen enough. %%
	label $htext(widget).logo -bitmap BLT -bd 1 -relief raised \
		-fg black 
    $htext(widget) append $htext(widget).logo -pady { 0 4 }
%%}
option add *Graph.halo			8i
option add *Graph.title			"Bitmap Symbols" 
option add *Graph.width			8i
option add *Graph.height		6i
option add *Graph.borderWidth		2
option add *Graph.relief		raised
option add *Graph.font	 		-*-helvetica-bold-r-*-*-18-*-*-*-*-*-*-* 

option add *Axis.TickFont 	-*-helvetica-bold-r-*-*-12*-*-*-*-*-*-* 
option add *Axis.TitleFont 	-*-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*
option add *y2.hide 		no
option add *degrees.stepSize		90 
option add *degrees.Command		formatXLabels 
option add *degrees.Subdivisions	0 
option add *degrees.Title		"Degrees" 
option add *degrees.Limits 	"T=%g"
option add *y.Limits		"%g"
option add *y.Title		"Y" 
option add *y.loose		no
option add *y.Color		purple2
option add *y.rotate		90 
option add *y2.rotate		270
option add *y2.color		magenta3
option add *temp.Limits 	"T=%g"
option add *temp.title		"Temperature"

option add *Legend.position 	plotarea
option add *Legend.anchor 	ne
option add *Legend.activeRelief raised
option add *Legend.activeBorderWidth 2
option add *Legend.font		-*-helvetica-medium-r-*-*-34-*-*-*-*-*-*-*
option add *Legend.relief	flat
option add *Legend.borderWidth  0

option add *Element.ScaleSymbols true
option add *Element*Pixels	2.75m

graph .graph

proc formatXLabels {graph x} {
     return "[expr int($x)]\260"
}

table . \
    .graph 0,0 -fill both  

table .frame .frame.msg -padx 20 

table configure . r1 -resize none
wm min . 0 0

set max -1.0
set step 0.2

set letters { A B C D E F G H I J K L }
set count 0
for { set level 30 } { $level <= 100 } { incr level 10 } {
    set color [format "#dd0d%0.2x" [expr round($level*2.55)]]
    bitmap compose symbol$count [lindex $letters $count] \
    	-font -*-helvetica-medium-r-*-*-34-*-*-*-*-*-*-*
    .graph pen create style$level -color $color -symbol symbol$count \
	-fill "" -pixels 6m
    set min $max
    set max [expr $max + $step]
    lappend styles "style$level $min $max"
    incr count
}

vector w x sinx cosx

.graph axis create temp -color blue -title Temp  -min -0.5 -max 0.5
.graph axis create degrees -color blue
.graph xaxis use degrees

set tcl_precision 15
.graph element create line1 \
    -label sin(x) -fill orange -color black -xdata x -ydata sinx  \
	-symbol "@bitmaps/hobbes.bm @bitmaps/hobbes.bmm" -pixels 6m \
		-fill yellow \
	-dashes { 10 4 } -linewidth 1 -mapx degrees

.graph element create line2 \
    -label cos(x) -color green4 -fill green \
	-xdata x -ydata cosx -weights w \
	-styles $styles -mapx degrees

set pi1_2 [expr 3.14159265358979323846/180.0]

puts stderr "Generating data..."
for { set i -360 } { $i <= 360 } { incr i 5 } {
    set x(++end) $i 
    set radians [expr $i*$pi1_2]
    set sinx(++end) sin($radians)
    set cosx(++end) cos($radians)
    set w(++end) cos($radians)
}

puts stderr "done."

Blt_ZoomStack $graph
Blt_Crosshairs $graph
#Blt_ActiveLegend $graph
Blt_ClosestPoint $graph
Blt_PrintKey $graph


#
# Put a scrolled listbox in the graph
#
frame .graph.win
listbox .graph.win.lbox \
	-width 10 -height 5 -yscrollcommand { .graph.win.sbar set }
eval .graph.win.lbox insert 0 [.graph pen names]
.graph.win.lbox selection set 0
scrollbar .graph.win.sbar -command { .graph.win.lbox yview }
table .graph.win \
    .graph.win.lbox 0,0 -fill both \
    .graph.win.sbar 0,1 -fill y
table  configure .graph.win c1 -resize none

.graph marker create window -name barney -coords "360.0 -1" \
	-window .graph.win -under true -anchor se

.graph postscript configure -maxpect yes -landscape yes
