py5coding / py5generator

Meta-programming project that creates the py5 library code.
https://py5coding.org/
GNU General Public License v3.0
52 stars 13 forks source link

(undocumented?) `clear()` function for the main "canvas" missing? #78

Closed villares closed 2 years ago

villares commented 2 years ago

In Processing Python mode the clear() function seems to work like background(0). As far as I can tell the background can't have transparent pixels.

I think this was added recently, maybe as an alias to make things similar to the p5js vocabulary?

The documentation tells us only about the PGraphics method :( https://py.processing.org/reference/clear.html

hx2A commented 2 years ago

I believe clear has been in Processing for a while, but it is only available for PGraphics. In the source code the comments say

   * Clears the pixels within a buffer. This function only works on
   * <b>PGraphics</b> objects created with the <b>createGraphics()</b>
   * function. Unlike the main graphics context (the display window),
   * pixels in additional graphics areas created with <b>createGraphics()</b>
   * can be entirely or partially transparent. This function clears
   * everything in a <b>PGraphics</b> object to make all of the pixels
   * 100% transparent.

It is a public method so py5 could offer it as a function in Sketch but that comment led me to believe that it should only be available for Py5Graphics. It is probably easier for p5 to provide a clear() function because the html canvas it is drawing to can be transparent. You are correct that Processing windows and therefore py5 windows cannot have a transparent background, which is why clear() is not made available to users. If it were I think it might be confusing or mislead users about what was possible.

villares commented 2 years ago

Just to be clear (pun intended), there is a clear() function available in Processing Python mode, and it paints the background black. :smile:

I'm afraid it is an undocumented feature. It is useful for #つぶやきProcessing :rofl:

hx2A commented 2 years ago

Since the clear() function isn't part of the Processing API, Python Processing probably shouldn't have included it, but including it doesn't do any harm. It wouldn't be harmful to py5 either, as long as it is documented properly. And I see how it would be helpful to #つぶやきProcessing as it saves 6 characters, which is an optimization I would appreciate. 😄 It's a small change and I'll add clear() to the next release.

hx2A commented 2 years ago

I'm having a productive day writing code and documentation for py5.