Peter Bako
Peter Bako

Reputation: 93

Filling in a circle using PIL

I'm trying to figure out how to draw a circle that can be filled to varying levels, from left to right signifying the phase of the moon. Final output will be to an ePaper display, so it only needs to be black and white. Using the ImageDraw method from the PIL library, I can draw a circle but cannot come up with any way to fill it. I tried to use the Arc method, thinking I can create smaller smaller arcs within the circle, but that always starts at the 3 o'clock position, whereas I would need it to start at the 12 o'clock location down to 6 o'clock.

New to Python (so code fragments would be appreciated). TIA

Upvotes: 0

Views: 407

Answers (1)

You need to edit your question and add the operating system because you need to install python package PIL using the pip tool or another tool DNF - for Fedora Linux: If you use Windows O.S or Mac O.S. the see this link.

The python source code for a circle fills with the color blue and outline green is this:

[mythcat@desk MonoProiects]$ python
Python 3.9.1 (default, Dec  8 2020, 00:00:00) 
[GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image, ImageDraw
>>> image = Image.new('RGBA', (100, 100))
>>> draw = ImageDraw.Draw(image)
>>> draw.ellipse((10, 10, 80, 80), fill = 'blue', outline ='green')
>>> image.save('circle_fill_with_outline.png')

The last row from the source code just saves this into a PNG image file. Some users use the new Pillow python packages.

Upvotes: 0

Related Questions