Making an ecosystem simulation

01 Dec 2025 - Jaxon

A screencap of my simulation. There is a button to spawn fish, which follow my cursor around the screen. There is a bright blue background and colorful, 8-bit hand-drawn fish floating around the screen. my current simulation

Over the summer, as i started getting into coding, I challenged myself to make a interactive ecosystem in p5.js. I got as far as adding in some ‘fish’, coding a basic physics engine with a buoyancy system for the water, and a simple seeking method.

I eventually gave up due to being inexperienced with javascript, and just not having the time or motivation to continue. I got the opportunity to choose a self-guided project for my second year in design school, and I thought it would be a good opportunity to try again.

In my first critique session, as I presented my project, I got a lot of interesting ideas, like having the simulation project on a large screen, or having users be able to submit their own drawings as fish. This got me excited about the project again, but I had to figure out how to actually make that, which was much more complicated than I thought it would be. To make a long story short, I had to create my p5.js sketch as a node.js app so that I could access a directory of image files on a local server. It was my first time using node.js, and my experience with it so far tells me I probably will not be touching it again for a good while. I eventually achieved what I needed to do, but looking back I probably should have just move over to Processing instead.

After finally figuring that out, I needed a few weeks to just not think about coding at all. This weekend I sat down to add some new features.

The first thing I wanted to do was to upgrade the physics library. I tried matter.js first, thinking it would be fun to have some collisions, but it got slow quickly. This definitely would not work for the amount of complexity im imagining for this project (schools of fish swimming on screen). I then tried toxiclibs.js, as recommended in Nature of Code, and althought it took a good while of digging to figure out how to use this library, I eventually was able to set up each fish as a particle with physics and boundary collision. So yeah, basically I spent about a whole lot of time just to end up back where I started. But I did learn a lot, and I think the additions I have in my code now will make things more manageable.

I also created a system that allows objects to seek out other objects. Right now, I am trying to fix some of the movement animations. I am working on making the fish rotate to follow the direction it’s headed, but the issue I’m having is that the Verlet physics integration is registering the current and the previous positions as being the same, which means I am not able to accurately calculate the velocity. Oh, and I’ve started to notice things gradually slowing as there are more and more particles, so either I’m going to have to look into how to optimize my code eventually, or I’m going to have to rewrite it in Processing(Java) at some point…

Anyways. This is just me trying to write down what I’m struggling with so I can maybe figure it out eventually. For now, I am going to take a break, enjoy the cozy weather and work on some other projects that I’ve been procrastinating.

Thanks for reading, If you’d like to check out the current state of this project check it out here on Github.

Feel free to reach out to connect and chat, or if maybe you have a solution to my problem!