Inspiration

This semester, I took a course on genetic algorithms, and it absolutely fascinated me. Nature has given us an incredibly powerful tool to estimate solutions for problems that are nearly unsolvable through brute force. One of my biggest inspirations for this project was Strandbeest, where genetic algorithms were used to determine the optimal limb lengths for mechanical creatures.

I’ve always been drawn to procedural generation, so I wanted to create my own system. That’s how RedPets was born—a project that lets communities collectively evolve their own subreddit mascots using genetic principles.

What it does

When the Devvit app is installed on a new subreddit, it initializes a starting population of creatures. Every time a user clicks the hatch button, two parent genes (explained below) are selected from the previous day's top posts. Through crossover and mutation(to be implemented), a new gene is generated, creating the user’s unique pet.

For the next 24 hours, subreddit members vote on different pets. The most upvoted creatures have a higher chance of becoming parents the next day causing their features to have a higher chance to show up. Over time, this system allows the subreddit to evolve its own mascot based on community preferences.

Genes Each creature is generated using a 33-bit gene that encodes various traits like body length, width, limb count, eye count, and more. As generations pass, the complexity and diversity of creatures naturally increase, leading to unique subreddit-specific evolution.

How I built it

Gene-Renderer - The core of this project is Gene-Renderer, a custom library I wrote that takes a 33-bit gene and converts it into a base64 image URL. This allows creatures to be rendered directly from their genetic code.

The library works by:

  • Extracting traits from the gene using bitwise masks.

  • Drawing the creature using the HTML canvas API.

  • Rendering key features like the torso, head, tail, and limbs based on genetic encoding and interpolation.

  • This runs on the Webview since blocks do not expose a document. WebView mounts takes in the gene returns the url and immediately unmounts.

I built this in just 2-3 days, so the implementation is a bit rushed, but it serves as a solid proof of concept!

Challenges I ran into

  • Generating organic shapes with SVG paths is tricky. While the current implementation works, there's room for improvement to make the shapes more natural and expressive.

  • Fine-tuning the crossover and mutation(to be implemented) rates was a challenge—too much randomness leads to chaos, but too little slows down evolution.

  • The blocks component does not provide a document element which the gene-renderer requires. However I was able to make it work with WebView.

  • JavaScript numbers are limited to 35–36 bits, so I had to carefully allocate bits for each trait. One major challenge was representing color. Each creature has two colors, both stored in 6-bit values. Instead of using three separate channels for RGB, I opted for HSL, mapping 6 bits (0–63) directly to hues (0°–360°). neat little trick!

Accomplishments that I'm proud of

Successfully built a genetic rendering engine from scratch.

Learned how to use Redis for caching and state management.

Came up with a unique interactive evolution system for subreddit communities.

What I learned

Explored how different species are structured and how locomotion affects limb positioning.

There’s likely a universal shape function that, with the right modifiers, could generate anything from a human to a grasshopper using the same genetic principles.

What's next for RedPets

The possibilities are endless! Here’s what I’d love to add:

  • More traits – spikes, patterns, poses, and more!
  • Increased detail – by using more bits per trait.
  • Cross-subreddit breeding – allow creatures to mix across different communities.
  • Site-wide mutation events – where every subreddit’s pet undergoes a sudden genetic shift.

I believe this concept has strong viral potential if executed correctly—similar in spirit to r/place, where collective participation drives a unique, evolving experience.

Built With

Share this project:

Updates