Created
September 19, 2022 23:02
-
-
Save ZhongxuanWang/877c61619eea6c9a507d72e9c559bdb9 to your computer and use it in GitHub Desktop.
Word Artist
This file contains 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
import cv2 | |
import numpy as np | |
import matplotlib.pyplot as plt | |
# Put your text here | |
words = 'word-art' | |
n_special_characters = 0 | |
for w in words: | |
n_special_characters += w.isalpha() | |
n_special_characters = len(words) - n_special_characters | |
words = words.upper() | |
img = np.zeros(shape=(100,90 * len(words) + n_special_characters * 45), dtype=np.int16) | |
cv2.putText(img=img, text=words, org=(0, 100), fontFace=cv2.FONT_HERSHEY_PLAIN, fontScale=9, color=(255, 255, 255),thickness=5) | |
plt.imshow(img) | |
img = np.flip(img, axis=1) | |
# [blue, orange, green] SUM < 1!! | |
color_weight = [0.7, 0.1, 0.2] | |
dot_density = 0.05 | |
xs_c1 = [] | |
ys_c1 = [] | |
xs_c2 = [] | |
ys_c2 = [] | |
xs_c3 = [] | |
ys_c3 = [] | |
for i in range(len(img)): | |
for j in range(len(img[0])): | |
if np.random.random() < dot_density and img[i][j] != 0: | |
if np.random.random() < color_weight[0]: | |
xs_c1.append(len(img[0]) - j) | |
ys_c1.append(len(img) - i) | |
elif np.random.random() < color_weight[0] + color_weight[1]: | |
xs_c2.append(len(img[0]) - j) | |
ys_c2.append(len(img) - i) | |
elif np.random.random() < color_weight[1] + color_weight[2]: | |
xs_c3.append(len(img[0]) - j) | |
ys_c3.append(len(img) - i) | |
plt.figure(figsize=(16,3)) | |
plt.axis('off') | |
plt.scatter(xs_c1, ys_c1) | |
plt.scatter(xs_c2, ys_c2) | |
plt.scatter(xs_c3, ys_c3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment