Skip to content

Instantly share code, notes, and snippets.

@grey-area
Created November 11, 2019 22:37
Show Gist options
  • Save grey-area/4dde16354c7521f121e63178d640fdad to your computer and use it in GitHub Desktop.
Save grey-area/4dde16354c7521f121e63178d640fdad to your computer and use it in GitHub Desktop.
import numpy as np
from PIL import Image
from matplotlib.colors import hsv_to_rgb
# Parameters
lim = 50
sub_pixel_resolution = 1
xs_min, xs_max = (-lim, lim)
ys_min, ys_max = (-lim * 0.5625, lim * 0.5625)
h_resolution = 1280 * sub_pixel_resolution
v_resolution = 720 * sub_pixel_resolution
xs = np.expand_dims(np.linspace(xs_min, xs_max, h_resolution), 0)
ys = np.expand_dims(np.linspace(ys_min, ys_max, v_resolution), 1)
hue = (np.sin(xs**2 + ys**2) + 1) / 4 + 0.5
s_and_v = np.ones_like(hue)
hsv = np.stack((hue, s_and_v, s_and_v), -1)
rgb = (255 * hsv_to_rgb(hsv)).astype(np.uint8).reshape(v_resolution, h_resolution, 3)
im = Image.fromarray(rgb)
im = im.resize(
(h_resolution // sub_pixel_resolution, v_resolution // sub_pixel_resolution),
Image.BICUBIC
)
im.save('radial.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment