|
tclspline
spline - Generate a set of quadratic splines based on an input list
Synopsisspline nSteps pointList spline_raw nSteps pointList MovedMoved to github tclspline project DescriptionInput is an integer number of steps, nSteps, and a list containing three or more pairs of x and y coordinates. spline reads that list and generates a new list of x and y coordinate pairs representing a curve based on the passed points, rendered as a set of quadratic splines: one spline is drawn for the first and second line segments, one for the second and third, and so on. Straight-line segments can be generated within a curve by duplicating the end-points of the desired line segment. spline_raw indicates that the list should also be returned as a curve, but the list of coordinates is such that the first coordinate pair (and every third coordinate pair thereafter) is a knot point on a cubic Bezier curve, and the other coordinates are control points on the cubic Bezier curve. Straight line segments can be generated within a curve by making control points equal to their neighboring knot points. If the last point is a control point and not a knot point, the point is repeated (one or two times) so that it also becomes a knot point. nSteps specifies the degree of smoothness desired for curves: eachspline will be approximated with nSteps line segments. |
Example Usage
package require tclspline set c [canvas .c] pack $c -expand 1 -fill both proc linecoords { y {amplitude 50}} { for {set i 0} {$i < 600} {incr i 55} { set sign 1.0 if { $i % 2 } { set sign -1.0 } lappend coords $i [expr {$sign * $amplitude + $y} ] } return $coords } set y 50 $c create line [linecoords $y] foreach {steps color} {2 skyblue1 5 skyblue2 10 skyblue3 50 orange2 100 orange3} { incr y 10 set coords [linecoords $y] set cmd [list set splinecoords [spline $steps $coords]] set duration [time $cmd] set t [format "% 14s for %4d steps" $duration $steps] puts $t set id [$c create line $splinecoords -fill $color] $c create text 20 [expr {$y * 1.5 + 80}] -text $t -fill $color -anchor w }Nice.. Thanks!