Week 4 – Generative Text

Concept: I really liked the example of using generative text to make poems so I decided to apply a similar approach to stories instead. The story randomly generates by pressing the mouse.

Code: The code I was proud of is that I found a way to simplify the example in the lecture notes. I did that by splitting the data once in setup to make things clearer then I used trim so any accidental extra spaces in the data is removed.

function setup() {
  createCanvas(500, 500);
  textAlign(CENTER);
  textFont('New Courier')
  
  // Split into different categories
  characters = split(words[0], ',');
  actions = split(words[1], ',');
  objects = split(words[2], ',');
  settings = split(words[3], ',');
  
  generateStory();
}
function generateStory() {
  let character = trim(random(characters));
  let action = trim(random(actions));
  let object = trim(random(objects));
  let setting = trim(random(settings));

Reflection and improvements: I really am proud of how things turned out. I wish I could have added more to the sketch to make it more entertaining. For example, I could replace the ellipse with a book to make it seem like the story is written on it.

Leave a Reply