Concept
For this project, I wanted to challenge myself and experiment with generative text output. I thought it would be interesting to create a program that builds short messages by mixing different pieces of text together. I wrote sentence templates with placeholders and then filled those placeholders with random words from lists of activities, places, events, and more. This approach makes every message different, even though they all follow a similar style. Each click shows a new message, so the text keeps changing and never feels the same. After eight messages, the conversation refreshes and starts again, so it feels like a brand-new chat every time. I also made the layout look like a chat screen, with colored message bubbles and a date at the top, so it feels like you are reading a conversation.
Highlight of the code I am proud of
The part I am most proud of is making the messages switch sides and look like a real chat conversation. As a beginner, figuring out how to alternate the chat bubbles between the left and right side was tricky, but using nextMessageIndex %2 to alternate sides worked perfectly.
// Interaction: add new message when mouse is pressed function mousePressed() { if (nextMessageIndex === 0) { messages = []; // clear canvas after 8 messages } let side; if (nextMessageIndex%2==0){ // Alternate sides side = 'left'; } else{ side= 'right'; } messages.push({ text: generateMessage(), side: side }); nextMessageIndex+=1; if (nextMessageIndex >= 8) { // Reset counter after 8 messages nextMessageIndex = 0; } }
Another thing I am proud of is the way I handled text wrapping. At first, I didn’t know how to make long messages fit inside the bubbles, but I learned how to split the text into words and build lines that stay within the bubble’s width. It made the conversation look clean and easy to read.
// Text wrapping into lines let words = m.text.split(" "); // Split message into words let lines = []; let tempLine = ""; for (let w of words) { // Check if adding word exceeds bubble width if (textWidth(tempLine + w + " ") < bubbleMaxWidth - 20) { tempLine += w + " "; // Add word to current line } else { lines.push(tempLine); // Save current line tempLine = w + " "; // Start new line with current word } } lines.push(tempLine); // Add last line
Sketch
Click the mouse to add a new message
Reflection
While making this project, I wanted to experiment with generative text output and see how random combinations of words could create a conversation. I am proud of how the messages alternate between left and right, making it feel like a real chat, and how the text wrapping keeps the messages neat inside the bubbles. For the improvements, I would like to add more templates and word lists to make the conversations even more interesting, maybe even including images in the chat bubbles. Also, one of the improvements would be adding a typing animation to make it feel more like a real conversation, and make it mobile-friendly so it works on smaller screens.