Sujet : improve a spline
De : saitology9 (at) *nospam* gmail.com (saito)
Groupes : comp.lang.tclDate : 12. Jun 2025, 17:51:58
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <102f0jf$2pouf$1@dont-email.me>
User-Agent : Mozilla Thunderbird
When you run the following code, a canvas comes up and you can click-hold your mouse and drag it around to create bezier curves.
The line is jagged and it has a double curve. I wonder if it is possible to make it smooth and reduce it to a plain s shape. Any ideas?
package req Tk
canvas .c -width 500 -height 500
pack .c -fill both -expand 1
bind .c <Button-1> [list mark %x %y]
bind .c <B1-Motion> [list draw %x %y]
proc mark {x y} {
set ::id 0
set ::ax $x
set ::ay $y
}
proc draw {x y} {
.c delete $::id
set xdiff [expr {($x - $::ax) / 2.0}]
set tx2 [expr {$::ax + 2 * $xdiff}]
set tx3 [expr {$x - 2 * $xdiff}]
set ::id [.c create line $::ax $::ay $tx2 $::ay $tx3 $y $x $y \
-fill #494949 -width 3 -smooth bezier -splinesteps 24]
}