How a Wuhan Student Used Python to Paint a Blooming Cherry Blossom from Pixels
A Wuhan University student turned the phrase “武汉加油” into thousands of colored pixels using Python, creating a time‑lapse cherry blossom animation that celebrates spring and supports the city, with step‑by‑step code for image generation, video assembly, and pixel‑level color handling.
After the COVID‑19 pandemic began to recede in China, Wuhan University opened a live broadcast of cherry blossoms, inviting people to enjoy spring online.
On March 18, a student from the School of Information Management, Zhu Yongchun, created a blooming cherry blossom entirely with Python code, using the phrase “武汉加油” (Wuhan, stay strong) as pixel elements.
The resulting image consists of many tiny characters, each representing a pixel whose color is defined by an RGB tuple.
Key steps of the program include:
Saving video frames as JPEG files with cv2.imwrite("pic/frame%d.jpg"%count, image).
Creating a blank RGB canvas and setting up a font with PIL:
blank = Image.new("RGB", [len(img[0]), len(img)], "white")
drawObj = ImageDraw.Draw(blank)
n = 10
font = ImageFont.truetype('C:/Windows/Fonts/Microsoft YaHei UI/msyhbd.ttc', size=n-1)Then a nested loop iterates over the image pixels, assigns the pixel color to the drawing object, and writes the appropriate character:
for i in range(0, len(img), n):
for j in range(0, len(img[i]), n):
text = '武汉加油'
drawObj.ink = img[i][j][0] + img[i][j][1]*256 + img[i][j][2]*256*256
drawObj.text([j, i], text[int(j/n) % len(text)], font=font)
print('完成处理——', i, j)
blank.save('new/new_'+pic, 'jpeg')Finally, the generated images are compiled into a video using OpenCV:
def picvideo(path, size):
filelist = os.listdir(path)
filelist = resort(filelist)
fps = 24
file_path = 'video/new.mp4'
fourcc = cv2.VideoWriter_fourcc('D','I','V','X')
video = cv2.VideoWriter(file_path, fourcc, fps, size)
for item in filelist:
if item.endswith('.jpg'):
img = cv2.imread(path + '/' + item)
video.write(img)
video.release()The complete source code is available for download, and the project demonstrates how thousands of “武汉加油” characters can be combined to form a blooming cherry blossom animation, symbolizing support for Wuhan.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
