It’s in the Cards: Building a Tarot Card Generator for Writing

Writer’s block, no matter the skill of the writer, is in the cards.

After falling into a writing slump one too many times, I decided to take that saying literally.

Tarot Cards and Creativity

Writing can be difficult, particularly when it comes to feeling blocked by a blank page. This is especially true during timed challenges like National Novel Writing Month. I’ve found that randomization, either through queries or prompt generators, can be a huge help in inspiring creative thought. Why not take it further, though, and make the randomization more robust?

Enter tarot cards.

Photo by Viva Luna Studios on Unsplash

Tarot cards have a long history of use in games, divination and self-discovery — and creativity. Each card has specific meanings attached to it, often connected to the symbolism of the card’s name and art. For example, the Death card sounds like a scary portent, but it can also be seen as a symbolic “death” or an ending.

Writers have drawn upon the symbolism of the tarot to feed into characterization. The Major Arcana, which includes the Death card, have been said to depict everything from life’s journey to Jungian archetypes. Likewise, the Minor Arcana, which uses suits, features royalty such as kings and queens, and you just know they have stories to tell.

Writers have used tarot cards as a way to inspire storytelling itself. Randomization becomes a groundswell of creativity. Whether doing readings for characters or pulling cards to inspire plot, combining internal symbolism and external randomness creates exciting juxtapositions.

This aspect of the tarot is what inspired this generator project initially. Still, if I just wanted to draw cards, there are online decks — or even physical cards — that could do the job. Instead, I wondered… could I create my own randomized Major Arcana?

Setting Up the Project

First, before even touching a line of code, I set out my objective: I wanted to be able to view a card that had a tarot-like feel that featured a random word and image, ideally connected in some way.

That objective in mind, I first created a card template in Canva, an online graphic design tool. The center was left blank to act as a window for the random images, while the borders gave the cards a minimalist tarot feel. I saved this as a transparent .png.

I opened up a fresh notebook and imported the image, setting it up with the template variable.

Next, I needed a random word — a noun — as well as a random photo to match that noun. The function RandomWord[] made this easy. Capturing this with the variable random, I used Capitalize[] to make sure that word was capitalized. This is similar to how cards in the Major Arcana are capitalized, such as with The Fool or The Magician.

As for the random photo, the resource function GetLoremFlickrImage[] looks for Creative Commons–licensed Flickr images based on prompts. By using the random variable for the search string, I was able to ensure that the image and text matched. (Well, as much as user-tagged content can match!)

I used the variable photo to connect the image request and random prompt. I requested images of a certain size. This made things look nicer on the card template.

The next thing I wanted to make sure of was that all generated cards started with “The.” While some cards in the Major Arcana don’t have “the” at the start, such as Wheel of Fortune, many do. For example, The Fool!

To do this, I set up a the variable, making sure to include a space, then concatenated the and random. Initial attempts to combine them resulted in weird, backward text. In the end, this is what worked:

Now things got a little trickier. I had my card name, which was fun, and an image, which was also fun, but how should I combine them with the template to produce a card?

The first hurdle was getting the text to be an image, which required rasterization. After some trial and error — and some Googling to see what others have done with their code — I came up with the following:

This code turned theRandom into an image, using the font Calibri and saving the result to a variable called textImage.

To combine everything, I used ImageCompose[] to stack it all together. In particular, I wanted to stack the template and photo, then the card and the text. It was important that the rasterized text be on the final, topmost layer.

To do this, I set up two variables:

The variable card is a basic composite, which was easy because both images were the same size. The finalCard variable required a bit of tweaking to make sure the text appeared at the correct place on the template. This was accomplished through the Scaled[] parameters. In this case, the text was centered (halfway, or .5) and moved around .15 up from the bottom.

And that was it! One code block for one randomized tarot card.

Pick a Card, Any Card…

Moment of truth. Oh, Writer’s Tarot, who is my main character?

Hm… A woman who wears crushed-velvet dresses, living in the past. She likes comfort and decadence.

What is she running from?

The Crustacean suggests a hard exterior and a need to keep people away. The image on the card, however, isn’t a crustacean at all, but is instead a fish. Our main character wears a mask of crabbiness in order to hide her soft side.

How might she overcome this battle?

The Fording implies movement, or travel. It is purposeful. This might not be literal travel; instead, it might indicate change, perhaps directed by an external force. This card also suggests baggage, and heavy baggage at that.

So Many Stories!

One possible story…

Once upon a time, a woman stuck in a dead-end job decided to make a career change after losing out on a big promotion. She tried to make her move but found her hard exterior holding her back. It was only after releasing her emotional baggage — the demoralization from the company — that she could be her authentic self. She landed a job at a vintage clothing store, selling the crushed-velvet dresses she loved in her youth.

Another story…

Once upon a time, a velvet-skinned alien found himself trapped in the stronghold of the hard-shelled Crustaceans. He pretended to be a Crustacean by hiding under tough scales, although if anyone chose to look closer, he’d be found out. He made his way through the walled city, looking for an escape. With help, he managed to ford an underground river, surviving the ordeal and returning home — perhaps a bit less soft, but alive.

And yet another story…

Danny was a country music star whose career was in shambles. Working at his father’s freight company to make ends meet after a disastrous gig, he met the smoky-voiced Velvet at a dive bar. She was crabby after discovering he’s a singer as well, fearful of losing her chance at impressing the music industry hotshot visiting their small town during an upcoming podcast roadshow. Danny became torn after realizing she was right: the executive could scout him….

Going Further

There is a universe of stories out there, and this little generator can help reveal them. That said, there are plenty of ways to improve on the code. Two ways in particular are allowing for multiple card draws at once and randomizing card position.

Creating a function or module would make the code easier to run. What’s more, that module could then be reused to allow for more complex “spreads,” or multiple cards being displayed at once. Imagine three cards shown in a row, or two cards crossed to form a plus sign.

In tarot, spreads allow for combinatory meaning. Two cards side by side might mean something very different than a card on its own. Likewise, some spreads take advantage of meaning in space. A card crossed with another leads to concepts blending together.

Cards being crossed suggests the other improvement: allowing for images to randomly display upside-down. While this seems like a bug, not a feature, it’s actually something used in some forms of tarot reading. A card might mean one thing, but the reversal — the card shown upside-down — means quite another.

Interestingly, my sparse code could help with this. The GetLoremFlickrImage[] resource function occasionally shows cards not fitting the image specs, which leads to them displaying with a red border in the template, like so:

In lieu of a true reversal, these red-border cards could be seen as reversals of a sort. In this case, The Countryman might be wicked, or disingenuous, or perhaps not a countryman at all!

Regardless, this generator has done its job. It’s broken through my writer’s block, revealing stories of crushed velvet and hard hearts. Maybe I should get back to writing instead of coding….

About the blogger:

Jesika Brooks

Jesika Brooks is an editor and bookworm with a Master of Library and Information Science degree. A lifelong learner herself, she has always been fascinated by the intersection of education and technology. She edits the Tech-Based Teaching blog (and always wants to hear from new voices!).

--

--

Tech-Based Teaching Editor
Tech-Based Teaching: Computational Thinking in the Classroom

Tech-Based Teaching is all about computational thinking, edtech, and the ways that tech enriches learning. Want to contribute? Reach out to edutech@wolfram.com.