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?
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.
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?
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?
This is the character of the Bezier smoothing. If you want a curve with
only a single "bent", you might consider to derive a midpoint from the
two endpoints and draw a smoothed line (-smooth 1) through THREE points.
A possible method:
- Take the vector from point A to point B
- Determine the normal n to that vector (note: choice of direction!)
- Use a fraction of the distance between A and B to calculate the new point:
new point = (A + B)/2 + fraction * distance(A,B) * normal vector
You have a number of choices here :).
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.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,064 |
Nodes: | 10 (1 / 9) |
Uptime: | 168:22:03 |
Calls: | 13,692 |
Calls today: | 2 |
Files: | 186,936 |
D/L today: |
10,547 files (3,117M bytes) |
Messages: | 2,411,602 |