Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add move_to method for Path #68

Open
charlesneimog opened this issue Dec 31, 2024 · 5 comments
Open

Add move_to method for Path #68

charlesneimog opened this issue Dec 31, 2024 · 5 comments

Comments

@charlesneimog
Copy link

Hi @agraef and @timothyschoen , happy end of 2024! 😄

I'm working on developing a library for handling simple scores using pdlua. https://github.com/charlesneimog/pd-score

I’m rendering music glyphs using the Bravura font and the d attribute for SVG path data (you can check out more details here: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d).

It works well, but I’m missing the move_to function on pdlua api. It’s essentially meant to move the cursor to a new position without drawing anything. I’ve tried implementing it myself using c, but I don't know anything about Tk, plugdata or PurrData.

For now, I’m using line_to, which almost works on low resolution but not or higher.

Here’s an example of what I’m seeing:

Pure Data

PurrData

Plug Data

Obs.: Create a new Path() does not work because the fill becomes wrong!

I believe this would be amazing not just for score, but would be possible to draw anything from svg.

@ben-wes
Copy link
Contributor

ben-wes commented Dec 31, 2024

@charlesneimog cool project! and would certainly be great to make svg drawing simpler that way (i tried to do that in a more complicated way by translating the svg paths to pdlua paths in https://github.com/ben-wes/pd-dualsense/blob/main/dsshow-shapes.lua )!

just adding this probably not surprising findings:

  • these glyphs are drawn by drawing paths inside other paths - so svg is doing an implicit boolean subtraction in that case if there's an overlap? anyway ... quite nice that this basically works already for all flavors!
    image

@agraef : i just realized that https://agraef.github.io/pd-lua/tutorial/pd-lua-intro.html doesn't mention the path drawing at all yet. i could make a draft for at least mentioning these methods briefly? or should this stay part of the help files only?

also, @charlesneimog's code made me realize that currently, pdlua's help mentions close_path() instead of close(), which is wrong.

@porres
Copy link
Contributor

porres commented Jan 22, 2025

wow, this would be really cool :) time to make a CAC tool for Pd like Open Music!

@timothyschoen can you tackle that for the next update?

@timothyschoen
Copy link
Contributor

I wonder: if you're only drawing the path instead of filling it, couldn't you just create a new Path instead of move_to?

The difficulty with a move_to function is that it would need to function correctly for drawing and filling. And filling a path with a hole in it might not be simple

@charlesneimog
Copy link
Author

charlesneimog commented Jan 31, 2025

I don't thing so @timothyschoen, mainly because of the subtraction that @ben-wes was talking about (I think).

This is the result for when I try to create a new Path

Image

--x, y = params[1] * scaling, params[2] * scaling
--p:line_to(x, y) -- NOTE: Should be move_to
x, y = params[1] * scaling, params[2] * scaling
p = Path(x, y)

The comment lines are the current implementation!

@ben-wes
Copy link
Contributor

ben-wes commented Jan 31, 2025

@charlesneimog that's what i meant, yes. svg's default is the nonzero fill-rule which will create a "hole" if the inner shape is described in the opposite direction; and there is evenodd, where the direction doesn't matter and it depends on the amount of layered shapes:
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule

move_to itself might not be the critical feature here if the same behaviour could also be achieved by closing the current path and subtracting another one from it. not sure how complex that would be though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants