py5book icon indicating copy to clipboard operation
py5book copied to clipboard

Fill issue

Open marziabil opened this issue 3 years ago • 3 comments

Hi! I have another question.

If you look at the open mouth method in this file (https://github.com/marziabil/emojis/blob/py5/mouth.py) - it has a fill feature. However, once the draw method is called from the emoji class, then the entire face gets filled in black. Is there a way to go around this? I'm facing this issue in other files too. I tried moving the fill feature but that's not working

Thanks in advance!

marziabil avatar Aug 10 '22 19:08 marziabil

I haven't run your code, but I am guessing you need to use py5.no_fill() after drawing the arc in openMouth()? The no_fill() method is how you turn off the filling of shapes.

I will also note that arc() can be influence by ellipse_mode(). It changes how the arc gets filled in, if at all.

hx2A avatar Aug 10 '22 21:08 hx2A

Just tried that. The issue then is that the rest of the emoji is white too :(

marziabil avatar Aug 11 '22 07:08 marziabil

When you call no_fill() or fill(), it affects all drawing commands that come after that. It doesn't matter if the Sketch is moving in and out of functions. It doesn't get reset when the function exits.

One recommendation is that at the beginning of each function, you set the fill to what you want it to be for that function. Then you know it will be correct for that function and you don't have to worry about if the Sketch will change if you call the functions in a different order.

Another approach is to use push_style() and pop_style() at the beginning and end of each function that sets the fill to something other than the default. Then the fill setting will be reset to the previous setting after the call to pop_style().

hx2A avatar Aug 11 '22 11:08 hx2A