On Thu, 12 Jun 2025 20:49:44 -0400
saito <
[email protected]> 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
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)