Introduction
Who would have thought that a t-shirt could inspire a creative coding project? Yet, this is exactly what happened for a passionate developer in the Re: Factor community. Stumbling upon a Uniqlo t-shirt featuring obfuscated Bash code, the author was inspired to create a fun program using Raylib, demonstrating how programming can serve noble causes like global peace.
The Context
The "Peace for All" campaign is an initiative led by Akamai, in collaboration with Uniqlo, to promote global peace. The idea was simple yet ingenious: print a snip of code on a t-shirt. This code, once decoded, reveals a message of peace.
The Technical Challenge
The article's author used OCR to convert the printed text into a string, which was then decoded using base64 --decode. This process reminded him of the days when he manually typed programs from computer magazines. The challenge was to recreate a similar program using Raylib with Factor, a functional stack-based programming language.
Implementation with Factor and Raylib
Basic Constants
To begin, the author defined some constants for the message, screen dimensions, and colors. The message "♥PEACE♥FOR♥ALL" is displayed in a circular manner, creating an infinite loop.
``factor CONSTANT: message $[ "♥PEACE♥FOR♥ALL" <circular> ] CONSTANT: width 800 CONSTANT: height 600 CONSTANT: font-size 24 ``
Drawing a Heart
The program needed to draw a heart since the default character set doesn't include this glyph. This is achieved by using circles and triangles to form the heart shape.
``factor :: draw-heart ( x y color -- ) ``
Animation and Color
The program uses a sine wave to animate the text display and gradually changes the colors from cyan to orange.
``factor : wave-x ( tick -- x ) : wave-color ( tick -- color ) ``
Rendering Loop
Each frame is rendered by drawing the glyphs for each line of text, creating a continuous animation.
``factor : render ( tick -- ) ``
Conclusion
This project demonstrates how even simple ideas can be transformed into innovative projects with a bit of creativity and passion for code. It also highlights the potential impact of coding to support important causes like peace. So, are you ready to use your coding skills for a better world?
Let's discuss your project in 15 minutes.