Adding boundary thickness parameter to the given circle code

135 Views Asked by At

I have this code that creates an image containing a circle. Now I want to add a boundary thickness parameter in the given code just like we can do in openCV.

Please help me with how can I add that to the given code.

Code:

from datetime import datetime

from random import randint

from PIL import Image


def circle(data, center, radius, color, size):

    for x in range(size):
        for y in range(size):
            if (x - center[0]) ** 2 + (y - center[1]) ** 2 <= radius ** 2:
                data[x * size  + y ] = color
    return data


def main():

    start_time = datetime.now()
    size = 400
    circle_centre = (int(size/2), int(size/2))
    circle_radius = circle_centre[0]
    circle_color = (0, 0, 0) 
    data = [(255, 255, 255)] * size ** 2  
    img = Image.new('RGB',(size,size),'white')

    data = circle(data, circle_centre , circle_radius , circle_color, size)
    img.putdata(data)
    img.show()
    img.save("circle.png", "PNG")
    print(f"Time needed: {datetime.now() - start_time}")


if __name__ == "__main__":
    main()
0

There are 0 best solutions below