how to fill a part of a circle using PIL?

Posted by valya on Stack Overflow See other posts from Stack Overflow or by valya
Published on 2010-06-02T22:33:40Z Indexed on 2010/06/02 22:34 UTC
Read the original article Hit count: 252

Filed under:
|
|
|

hello.

I'm trying to use PIL for a task but the result is very dirty.

What I'm doing is trying to fill a part of a piece of a circle, as you can see on the image.

Here is my code:

def gen_image(values):

side = 568
margin = 47
image = Image.open(settings.MEDIA_ROOT + "/i/promo_circle.jpg")

draw = ImageDraw.Draw(image)
draw.ellipse((margin, margin, side-margin, side-margin), outline="white")

center = side/2
r = side/2 - margin

cnt = len(values)

for n in xrange(cnt):
    angle = n*(360.0/cnt) - 90
    next_angle = (n+1)*(360.0/cnt) - 90
    nr = (r * values[n] / 5)

    max_r = r
    min_r = nr

    for cr in xrange(min_r*10, max_r*10):
        cr = cr/10.0
        draw.arc((side/2-cr, side/2-cr, side/2+cr, side/2+cr), angle, next_angle, fill="white")

return image

© Stack Overflow or respective owner

Related posts about python

Related posts about image