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
Could Py5Shape objects have a .width and a .height using @property? #352
Comments
Sure, let's add it, along with When I first started making py5 I had to go through literally thousands of public methods and variables to determine what should be included in the API and what should be left out. As I've learned more about Processing I've found places where I didn't make the right decision. Which is fine, it is an easy thing to correct. All of the include / exclude decisions are stored in CSV files. In some cases there are comments explaining why something is the way it is. |
This looks like something related I 'd like to investigate. I can't reproduce this at will yet, so I'll drop this here as a reminder of my thoughts. py5 encountered an error in your code:
File "/home/villares/GitHub/sketch-a-day/2023/sketch_2023_09_23/sketch_2023_09_23.py", line 40, in draw
24 def draw():
(...)
36 elif isinstance(thumb, py5.Py5Image):
37 rw = thumb.width
38 func = py5.image
39 elif isinstance(thumb, py5.Py5Shape):
--> 40 w, h = thumb.get_width(), thumb.get_height()
41 ratio = w / h
..................................................
w = 64.0
h = 64.0
..................................................
AttributeError: 'NoneType' object has no attribute 'getWidth' Note how weird, I know |
How was the Py5Shape instance Remember, the Python class In general, Processing isn't so good at reading SVG files it did not create itself. It does not know the full SVG specification so your approach here will not work for all SVG files. One approach is to use |
Ohhh, this will be handy! I hadn't realised (or maybe I forgot) |
It really ought to be better documented. That's why I want to create an "Integrations" section in the documentation to specifically document py5's integrations with other libraries. It's one of the strengths of the library, in that it can help educators like yourself branch out into the Python ecosystem within in the context of creative coding.
Did you open a new issue? I can't find it. In any case, py5 should never return a malformed Py5Shape object. Right now it specifically checks for Java exceptions from Processing's |
Thank you! Not that new, not related to this, so I'll break the URL: https://github.com/processing/processing4/issues/ 750 I think other people will be able to add more integrations in the future. imageio has a plug-ins system: https://imageio.readthedocs.io/en/stable/reference/index.html#plugins-backend-libraries |
Yes! py5's imageio looks useful! Thanks for pointing out. Certainly reading SWF files would be a great addition to py5. |
So the reason why I didn't create py5.println(s.width, s.height, s.depth)
py5.println(s.get_width(), s.get_height(), s.get_depth()) 0.0 0.0 0.0
1.135807752609253 2.82108998298645 5.444699764251709 But I can re-address this by creating properties in Python and having them call the Java methods |
It is well documented that Py5Image and Py5Graphics have
.width
and Py5Shape has.get_width()
instead...I suppose this is a way of showing dimensions of Py5Shapes are mutable, but I was a bit surprised and decided to check how it looks in Processing Java.
PShape
objects have.width
.Could the interface perhaps be unified for ergonomic reasons? Or is it a bad idea?
The text was updated successfully, but these errors were encountered: