Tk Source Code

Artifact [5e8041a6]
Login

Artifact 5e8041a6ad2c5b3115aab7ef87ed06efe39966e8:

Attachment "demo.tcl" to ticket [630171ff] added by dgp 2002-10-29 06:14:22.
# Source this into wish. Test with
#
#   drawlines [makepts $count] $width
#   
# where $count is number of points, $width is width of lines
# in pixels.
#
# Works well on unix.  Time required depends linearly on the
# number of points, with thick lines (width>1) taking only
# marginally longer than thin lines.
#
# On Windows, thin lines (width=1) work well, with time
# required depending linearly on the number of points.
# Thick lines are rendered slowly, with time required
# increasing much worse than linear once the number of
# points is more than say 100.  On my Win98 box, with
# Tcl/Tk 8.4.1, 'drawlines [makepts 1638] 2' raises
# an illegal operation fault.  More points than this
# results in nothing being drawn.  On Win2k, system
# response becomes very sluggish as the number of points
# moves into the thousands.

set canvas_width 301
set canvas_height 301

set canvas .c
if {[winfo exists $canvas]} {
    $canvas delete all
    $canvas configure -width $canvas_width -height $canvas_height \
	-background white
} else {
    canvas $canvas -width $canvas_width -height $canvas_height \
	-background white
    pack $canvas
}

proc makepts { count } {
    global canvas_width canvas_height
    for {set i 0} {$i<$count} {incr i} {
	set x [expr {$i%$canvas_width}]
	set y [expr {($i%2)*$canvas_height}]
	lappend pts $x $y
    }
    return $pts
}

proc drawlines { pts width } {
    global canvas
    $canvas delete all
    $canvas create line $pts -width $width
}

#drawlines [makepts 500] 2