Sujet : Re: improve a spline
De : emil.g (at) *nospam* example.invalid (Emiliano)
Groupes : comp.lang.tclDate : 13. Jun 2025, 14:19:09
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250613101909.3d7408fa23e1045a225f6de9@example.invalid>
References : 1 2 3
User-Agent : Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu)
On Thu, 12 Jun 2025 20:49:44 -0400
saito <
saitology9@gmail.com> wrote:
On 6/12/2025 7:08 PM, Emiliano wrote:
If by "smooth" you mean antialias, then no, Tk canvas doesn't do antialias.
As I undertand it, the tkpath package does, but I can't confirm since never
used it.
Thanks for taking a look. This is a piece of very old code from someone
else and I need to decide whether to improve it or trash it.
I guess there is no escaping the jagged lines. That is OK. How about
just making it a simple curve? As it is currently, there are two points
where it curves making it look like an S. Any ideas to reduce it to
simple / relaxed sine curve?
See the "-smooth raw" option. With this option you can define the spline
control points. In the following code, circles are knot points (coordinate
pairs 0, 3, 6 ...) and the squares are control points (coordinate pairs 1, 2,
4, 5 ...). Try moving the points around.
Sample code: ==================================================
package require Tk
proc lexpr {args} {
lmap expr $args {uplevel 1 [list expr $expr]}
}
proc point-coords {x y} {
lexpr {$x-5} {$y-5} {$x+5} {$y+5}
}
proc move-node {c item idx x y} {
set x [$c canvasx $x]
set y [$c canvasy $y]
$c coords $item [point-coords $x $y]
$c rchars line {*}[lexpr {$idx*2} {1+2*$idx}] [list $x $y]
}
canvas .c -xscrollcommand [list .sx set] -yscrollcommand [list .sy set]
ttk::scrollbar .sy -orient vertical -command [list .c yview]
ttk::scrollbar .sx -orient horizontal -command [list .c xview]
grid .c .sy -sticky news
grid .sx -sticky ew
grid columnconfigure . 0 -weight 1
grid rowconfigure . 0 -weight 1
set coords {50 150 100 250 150 50 200 150}
set idx 0
.c create line $coords -smooth raw -tags line -splinesteps 20
foreach {x y} $coords type {oval rectangle rectangle oval} {
set item [.c create $type [point-coords $x $y] -fill red]
.c bind $item <B1-Motion> [list move-node %W $item $idx %x %y]
incr idx
}
bind .c <ButtonRelease-1> {%W configure -scrollregion [%W bbox all]}
.c configure -scrollregion [.c bbox all]
==================================================
Regards
-- Emiliano