Skip to content

Instantly share code, notes, and snippets.

@evanthebouncy
Created July 18, 2019 20:24
Show Gist options
  • Save evanthebouncy/0411b68b336baa4e8e3afab997d07b40 to your computer and use it in GitHub Desktop.
Save evanthebouncy/0411b68b336baa4e8e3afab997d07b40 to your computer and use it in GitHub Desktop.
cross
from PIL import Image, ImageDraw
import numpy as np
L = 1028
img = Image.new('RGBA', (L, L), (255, 0, 0, 0))
center = (L / 2, L / 2)
def scale_w_by_d(d):
return int(d / (L / 2) * 32)
def scale_alpha_by_d(d):
return 255 - int(d / (L / 2) * 255)
draw = ImageDraw.Draw(img)
for i in np.linspace(0, L, 17):
for j in np.linspace(0, L, 17):
dd = np.sqrt((i - L / 2) ** 2 + (j - L / 2) ** 2)
if dd > L / 2:
continue
delx, dely = center[0] - i, center[1] - j
l = np.sqrt(delx ** 2 + dely ** 2)
# edge case
if l == 0: continue
delx_norm, dely_norm = delx / l * 32 , dely / l * 32
end_i, end_j = i + delx_norm, j + dely_norm
ww = scale_w_by_d(dd)
aa = scale_alpha_by_d(dd)
draw.line((i, j, end_i, end_j), fill=(255, 0, 0, aa), width=ww)
img.save('cross.png', 'PNG')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment