For my final project, I created an interactive textile pattern generator called Persian Rug Machine. The project lets the user create decorative rug-like compositions using a custom Arduino controller connected to p5.js. Instead of drawing directly on the screen, the user changes the design through six physical arcade buttons. I wanted the project to feel like a small textile machine where the user can build a visual composition through touch.
Github link
game demo

The project changed a lot while I was developing it. I first planned to use buttons, potentiometers, and a joystick. I also tested a fighting stick controller, but I eventually returned to Arduino because it matched the assignment better and made the physical communication with p5.js more central. I also decided not to use the joystick because the rug looked stronger when the center medallion stayed centered. Simplifying the controller made the interaction clearer and more intentional.
The final controller uses six buttons. Each button sends a command from Arduino to p5.js through serial communication. The buttons control motif shape, color palette, background color, line style, center medallion style, and finish/save. This gave the user enough creative control without making the interface too confusing.
The visual inspiration came from Persian rugs, embroidery, floral textile motifs, geometric ornament, and tiled decorative systems. I focused on repetition, symmetry, borders, central medallions, and controlled color palettes so the patterns would feel intentional instead of random. I wanted the final compositions to feel decorative and textile-like, not just like shapes moving on a screen.
The Arduino side reads the buttons using Input_Pullup. When a button is pressed, Arduino sends a text command such as “motif”, “palette”, or “finish” to p5.js. Then p5 reads the command and changes the rug design.
if (command === "motif") {
patternMode = (patternMode + 1) % 3;
}
if (command === "background") {
bgColorIndex = (bgColorIndex + 1) % bgColors.length;
}
if (command === "finish") {
state = "final";
setTimeout(() => {
saveCanvas("DIY-Persian-rug", "png");
}, 300);
}
One part of the code I am proud of is the repeated motif system. I used nested loops to place motifs across the screen in a structured grid, which helped the rug feel more like a textile composition.
for (let i = 0; i <= cols; i++) {
for (let j = 0; j <= rows; j++) {
I also used distance from the center medallion to scale the motifs, which made the composition feel more layered and less flat.
let d = dist(x, y, centerX, centerY); let s = map(d, 0, width * 0.7, tileSize, tileSize * 0.45);
I separated the motifs into different functions, such as drawDiamondMotif(), drawFloralMotif(), and drawStarMotif(). This made the code easier to organize and allowed the user to switch between motif styles in real time. I also included borders, straight lines, and zigzag lines to make the composition feel closer to woven or embroidered designs.
I added oud background music using p5.sound and a custom font to make the project feel more complete. I also removed the bottom instruction panel from the studio screen because the physical buttons are already labeled, so the screen can focus more on the rug itself.
The biggest challenge was balancing creative freedom with visual cohesion. At first, adding too many controls made the results feel chaotic. Simplifying the controller to six clear buttons made the project easier to use and made the final rug designs feel more intentional. Another challenge was making the Arduino-to-p5 communication clear, so I used labeled text commands instead of only sending numbers.
Overall, I am proud of how the project became a small custom textile machine. The user physically presses buttons to shape the rug, and the final button presents and saves the completed design. I like that the final version connects the physical controller and the digital pattern in a clear and direct way.
references:
- sound: https://pixabay.com/sound-effects/musical-oud-c-arabian-400521/
- buttons: https://amzn.eu/d/0b8s4vBb
Pinterest inspiration:












