Last active
July 29, 2020 18:45
-
-
Save idling-mind/66b52eb3578e1315f75254610fcf7943 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image, ImageDraw | |
scale_factor = 4 # Resize scaling for antialiasing | |
img_size = (500, 500) # Final image size desired | |
img_size_scaled = tuple(x*scale_factor for x in img_size) | |
img = Image.new("RGB", img_size_scaled) | |
ic = ImageDraw.Draw(img, "RGBA") # Specified RGBA | |
def draw_circle(x, y, r, color): | |
"""Function to draw a circle at given center with given | |
radius and colour | |
""" | |
x, y, r = int(x), int(y), int(r) # Converting possible floats to int | |
ic.ellipse([x-r, y-r, x+r, y+r], fill=color) | |
for i in range(10): | |
draw_circle( | |
img_size_scaled[0]/2, img_size_scaled[1]/2, | |
img_size_scaled[0]/2*(10-i)/10, | |
(255, 0, 0, int(100*i/10)) | |
) | |
# You can pass in list of tuples too! | |
img = img.resize(img_size, resample=Image.ANTIALIAS) | |
img.save("basic_opacity.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment