background-shape
feature-image

Writing poetry with Tracery, a text-generation JS library

I’ve been playing around with Tracery recently: it’s a perfect casual creator tool, easy to pick up, simple, and powerful. I figured a valentine generator would be a fun little project, so I scribbled out some sentences one day, while procrastinating over something else.

🌹 Try it out here! Just refresh the page for new versions. 🌹

Code

Here’s the entire Tracery grammar that makes My Generated Valentine. It’s really simple, built around just a few sentence structures.

The writing process looks something like this:

  1. Write a sentence, for example: “I ❤️ you like a 🌈🐱.”
  2. Within each sentence, each emoji represents a variable, which can be replaced by any number of words.
  3. Write out the list of words that could replace each emoji. For example, ❤️ can be “love”, “trust”, “adore” and so on. 🌈 can be “happy” or “mad”, and 🐱 can be “cat” or “tree”.
  4. That’s it! Mix and match: the final sentence is a random selection of words from each list, in the same sentence structure.

Breaking it down

Here are the 11 sentence structures I used, with emojis for readability:

  1. I ❤️ you like a 🔥 🌈 🐱.
  2. I will always ❤️ you like a 🌈 🐱.
  3. Do you really ❤️ me, like a 🌈 🐱?
  4. I’ll 🙆‍♀️ you like a 🌈 🐱.
  5. Will you 🙆‍♀️ me like a 🔥 🌈 🐱?
  6. Even if you were a 🌈 🐱, I’d still 🙆‍♀️ you.
  7. If you were a 🌈 🐱, I’d be a 🔥 🌈 🐱.
  8. Will you be my 🌈 🐱?
  9. Let me be your 🌈 🐱 forever.
  10. To be mine, you must be as ⭐️ as a 🌈 🐱.
  11. For you, I will be as ⭐️ as a 🌈 🐱.

Guess what #10 and #11 are homages to?

Romantic Replaceability

One reason for a valentine generator was that the simplest declarations of love could be turned around and posed as questions: “I ❤️ you like a 🌈🐱” becoming “Do you really ❤️ me, like a 🌈🐱?”

I also figured that sentences with ‘you’ and ‘I’ are possibly the shortest ones that sustain interest!

Without speaking of literary merit, it was an exercise of getting the most variation out of limited ingredients, and some laughs as well.

For more on Tracery, here’s a great interactive tutorial by its creator.

Takeaways

Little experiments like this make me happy. I’m glad I got the chance to play around with Tracery, as well as CSS and HTML, to make something that people can have fun with.

Technically, I’m proud of a little more familiarity with Github respositories and pages, and successful CSS/HTML googling (vertically aligning text, gradients, linking fonts, doctype and quirks mode)!

P.S. My Generated Valentine has been called “super cute” and “a useful aid to all men during valentines in need of words”.