Skip to content

Instantly share code, notes, and snippets.

@bhawkins
Last active December 17, 2024 07:16
Show Gist options
  • Save bhawkins/eab6653a8ac08921635c74dc624bedb7 to your computer and use it in GitHub Desktop.
Save bhawkins/eab6653a8ac08921635c74dc624bedb7 to your computer and use it in GitHub Desktop.
Wrapped holiday gift for Liana
import PIL
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
# screenshot of Google Sheet with "Liana" written in 72 pt Pacifico font
text_img = PIL.Image.open("liana_text.png")
text_rgba = np.array(text_img)
text_gray = 1 - np.sum(text_rgba[..., :3], axis=-1) / (255 * 3)
y = np.linspace(0, 1, text_gray.shape[0])
x = np.linspace(0, 1, text_gray.shape[1])
z = np.outer(y, x)
wrapped = ((z * 10 - text_gray) % 2) / 2
cmy = LinearSegmentedColormap('cmy', {
'red': ((0.000, 0.0, 0.0),
(0.333, 1.0, 1.0),
(0.666, 1.0, 1.0),
(1.000, 0.0, 0.0)),
'green': ((0.000, 1.0, 1.0),
(0.333, 0.0, 0.0),
(0.666, 1.0, 1.0),
(1.000, 1.0, 1.0)),
'blue': ((0.000, 1.0, 1.0),
(0.333, 1.0, 1.0),
(0.666, 0.0, 0.0),
(1.000, 1.0, 1.0))
})
wrapped_colored = np.asarray(cmy(wrapped) * 255, dtype="uint8")
img_out = PIL.Image.fromarray(wrapped_colored)
img_out.save("liana_phase.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment