Concept
In this p5.js sketch, my main objective was to practice the use of classes and arrays. In my sketch, little objects called “walkers” wander randomly across the canvas, leaving behind the trail that slowly fades away. Each walker has its properties (see below in Code Highlight part), which are determined randomly at the moment of creation (user click).
Demo (Click on canvas)
Code Highlight:
The core of this sketch is the Walker
class. It encapsulates everything each walker needs to function:
// Walker class definition class Walker { constructor(x, y) { this.x = x; this.y = y; // Give each Walker a random color this.col = color(random(255), random(255), random(255)); // Control how quickly it moves around this.stepSize = random(1, 3); } update() { // Randomly move the walker in x & y directions this.x += random(-this.stepSize, this.stepSize); this.y += random(-this.stepSize, this.stepSize); // Keep the walker within the canvas boundaries this.x = constrain(this.x, 0, width); this.y = constrain(this.y, 0, height); } show() { noStroke(); fill(this.col); ellipse(this.x, this.y, 8, 8); } }
Inside this class, the update() method adjusts the walker’s position in small random increments, while show() draws a small ellipse at its current location.
The background(0, 13) call in the draw() loop is also important because it uses transparency to slowly erase the walkers’ paths, creating the glowing trails of each walker (I think it looks kinda cool).
Reflection & Improvements for Future Work
First of all, it was really entertaining to watch each walker wander around, leaving a trail. By simply changing parameters like number of walkers, their step size, or fade value in the background, one could produce unique versions of this piece.
In the future, I would love to make sure that the walkers of the same color would interact with each other (mixing together and creating a bigger walker). Another interesting idea would be to incorporate music in this piece (maybe 90s like Jungle beat) -> this way each walker would change its size/movement speed/direction based on the song.
If one would think long enough, the possibilities for making this piece more immersive and dynamic are essentially limitless.
Maybe one could make a game out of this piece, who knows?