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
|
# ------------------------------------------------------------------
# Simple Mathematical Function Plotter
#
# Plots mathematical functions and makes GIF images.
# Primarily intended to be an interesting example, not a full
# fledged package.
# ------------------------------------------------------------------
load ./gifplot.sl
source plot2d.tcl
source display.tcl
# Create a framebuffer and plot
set f [FrameBuffer -args 400 400]
set cmap [ColorMap -args "cmap"]
set p2 [Plot2D -args $f -6.3 -2 6.3 2]
set xmin -6.3
set xmax 6.3
set ymin -2.0
set ymax 2.0
set xtick 3.1415926
set ytick 0.5
set title Plot
set xaxis_label X
set yaxis_label Y
set symbol NULL
set npoints 100
set color $YELLOW
set func "sin(x)"
set imageno 0
set filename plot0.gif
set autoinc 1
# Make a plot from the above parms
proc make_plot {} {
global p2 xtick ytick title xaxis_label yaxis_label color symbol func npoints filename cmap
global xmin ymin xmax ymax imageno autoinc
$p2 setrange $xmin $ymin $xmax $ymax
newplot $p2 $xtick $ytick $title $xaxis_label $yaxis_label
plotfunc $p2 $func $npoints $color $symbol
[$p2 cget -frame] writeGIF $cmap $filename
display_image $filename $p2 set_zoom
if {$autoinc == 1} {
incr imageno 1
set filename plot$imageno.gif
}
}
# Create a few frames
frame .title -relief groove -borderwidth 1
label .title.name -text "GIF Function Plotter (2D)"
button .title.quit -text "Quit" -command "exit"
button .title.about -text "About" -command "about"
pack .title.name -side left
pack .title.quit .title.about -side right
frame .func -relief groove -borderwidth 1
frame .func.f
label .func.f.flabel -text "Function" -width 12
entry .func.f.func -textvar func -width 45
pack .func.f.flabel .func.f.func -side left
frame .func.xrange
label .func.xrange.xrlabel -text "X range" -width 12
entry .func.xrange.xmin -textvar xmin -width 8
label .func.xrange.xtolabel -text "to"
entry .func.xrange.xmax -textvar xmax -width 8
pack .func.xrange.xrlabel .func.xrange.xmin .func.xrange.xtolabel .func.xrange.xmax -side left
label .func.xrange.xtickl -text "Tickmarks "
entry .func.xrange.xtick -textvar xtick -width 10
pack .func.xrange.xtick .func.xrange.xtickl -side right
frame .func.yrange
label .func.yrange.yrlabel -text "Y range" -width 12
entry .func.yrange.ymin -textvar ymin -width 8
label .func.yrange.ytolabel -text "to"
entry .func.yrange.ymax -textvar ymax -width 8
pack .func.yrange.yrlabel .func.yrange.ymin .func.yrange.ytolabel .func.yrange.ymax -side left
label .func.yrange.ytickl -text "Tickmarks "
entry .func.yrange.ytick -textvar ytick -width 10
pack .func.yrange.ytick .func.yrange.ytickl -side right
frame .func.npoints
label .func.npoints.label -text "N Points " -width 12
entry .func.npoints.npoints -textvar npoints -width 8
pack .func.npoints.label .func.npoints.npoints -side left
pack .func.f .func.xrange .func.yrange .func.npoints -side top -fill x
frame .appear -relief groove -borderwidth 1
# Appearance (labels )
frame .appear.text
frame .appear.text.title
label .appear.text.title.label -text "Title" -width 12
entry .appear.text.title.title -textvar title -width 20
pack .appear.text.title.label .appear.text.title.title -side left
frame .appear.text.xlabel
label .appear.text.xlabel.label -text "X Axis Label" -width 12
entry .appear.text.xlabel.title -textvar xaxis_label -width 20
pack .appear.text.xlabel.label .appear.text.xlabel.title -side left
frame .appear.text.ylabel
label .appear.text.ylabel.label -text "Y Axis Label" -width 12
entry .appear.text.ylabel.title -textvar yaxis_label -width 20
pack .appear.text.ylabel.label .appear.text.ylabel.title -side left
pack .appear.text.title .appear.text.xlabel .appear.text.ylabel -side top -fill x
# Appearance (symbols)
frame .appear.symbol
label .appear.symbol.label -text "Symbol"
radiobutton .appear.symbol.none -text "None" -value NULL -variable symbol -anchor w
radiobutton .appear.symbol.square -text "Square" -value $SQUARE -variable symbol -anchor w
radiobutton .appear.symbol.triangle -text "Triangle" -value $TRIANGLE -variable symbol -anchor w
radiobutton .appear.symbol.cross -text "Cross" -value $CROSS -variable symbol -anchor w
pack .appear.symbol.label .appear.symbol.none .appear.symbol.square .appear.symbol.triangle .appear.symbol.cross -side top -fill x
pack .appear.text .appear.symbol -side left -fill x -anchor n
# Filename dialog
frame .save -relief groove -borderwidth 1
frame .save.file
label .save.file.label -text "Save as" -width 12
entry .save.file.filename -textvar filename -width 20
pack .save.file.label .save.file.filename -side left
checkbutton .save.file.auto -text "Auto increment" -variable autoinc -anchor w
pack .save.file.auto -side left
pack .save.file -side top -fill x
button .save.go -text "Plot" -command "make_plot"
pack .save.go -side right
bind .save.file.filename <Return> {make_plot}
pack .title .func .appear .save -side top -fill both
proc about { } {
toplevel .about -width 350
message .about.m -text "\
GIF Function Plotter\n\n\
Copyright (c) 1997\n\
Dave Beazley\n\
University of Utah\n\n\
Creates simple 2D plots in the form of GIF files. Simply enter \
a mathematical expression in 'x' and press 'Plot' to make an image. Images \
can be zoomed by clicking in the displayed image and dragging.\n\n\
Disclaimer : This is not intended to be a full-fledged plotting package.\n" -justify left
button .about.okay -text "Ok" -command {destroy .about}
pack .about.m .about.okay -side top
focus .about.okay
}
|