Deutsch   English   Français   Italiano  
<20250613101909.3d7408fa23e1045a225f6de9@example.invalid>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Emiliano <emil.g@example.invalid>
Newsgroups: comp.lang.tcl
Subject: Re: improve a spline
Date: Fri, 13 Jun 2025 10:19:09 -0300
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <20250613101909.3d7408fa23e1045a225f6de9@example.invalid>
References: <102f0jf$2pouf$1@dont-email.me>
	<20250612200845.11f07fb082877f7af0527126@example.invalid>
	<102fsj8$30raj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 13 Jun 2025 15:19:10 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="06d9f7e2a94f5a1ad306af4797754204";
	logging-data="3628591"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19uMWFhJEummYmHYreThx/xeeGgkDZBYLo="
Cancel-Lock: sha1:RJXz45BB0lXV+A75qU4mmIE52yk=
X-Newsreader: 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