Concept:
After learning about the different loops in P5.js, I wanted to create a simple yet soothing code. That’s when I remembered a game I used to play as a kid. When I moved the cursor around the screen, all the points scattered away from it. It was a basic game, just rolling a ball around a screen, but there was something oddly satisfying about seeing the points move away from me.
So, I decided to recreate that game in my code. I used a loop to keep generating points randomly, making sure they never stopped appearing. Then, I added a bit of trigonometry to make it look like the points changed direction when they got close to the cursor. This gave the illusion that they were all moving away from the cursor, following the ball’s lead. It was a fun way to bring back a childhood memory through code.
A highlight of some code that you’re particularly proud of:
let d = dist(random1, random2, mouseX, mouseY);
if(d < 50)
{
let angle = atan2(random2 - mouseY, random1 - mouseX);
random1 += cos(angle) * 2;
random2 += sin(angle) * 2;
point(random1,random2);
As I scoured the internet in search of a function that could calculate the distance between the cursor and the points, I stumbled upon the ‘dist’ function, and it was exactly what I needed. Delving into the p5 references, I delved into trigonometric equations, studying their inputs and outputs. Through a series of trials and errors, I played around with the code, hoping for it to be similar to that childhood game. I’m pleased to share that the outcome exceeded my expectations and turned out rather well.
Reflection and ideas for future work or improvements:
Discovering the potential of loops in programming has ignited my imagination for creating games and sketches, and it’s incredibly thrilling. Although the sketch is already promising, I see room for enhancement by incorporating a diverse palette of colors and trails that follow the ball’s movement. Additionally, I aim to optimize the program’s performance to reduce any glitches caused by its rapid execution. Looking ahead, I envision using both ‘for’ and ‘while’ loops to craft even more imaginative games, such as a maze, and bring forth fresh interactive experiences.