Old P5.js Projects
Below you will find a few of my old projects that I have kicking around. Unfortunately I don’t really have much documentation for most so I can’t really write much about them. But this page will act as a home for them. Eventually I hope to revisit some of these projects and rewrite them. Though likely not using P5.js.
Ecosystem Simulation
This project is a simple eco system simulation. With each running of the simulation starting off with two “rabbits.” A male and a female which are blue and red respectively. Every frame they perform an action based on their current condition and environment. With them only being able to perceive a small area around them.
The actions they can take are limited to finding and consuming food and water as well as breeding. And if the rabbits are not hungry, thirsty, or able to breed they will begin traveling to a random point within their view.
Their life is limited in time as well. With it being possible for them to be born, age to maturity, and then die of old age. All the while they pass on their “genetic traits” to their offspring. With the traits and their affects being listed in the following table.
Trait | Affects |
---|---|
Rate | Determines how long the term of the pregnancy is as well as how many are in a litter. Also affects how frequently the rabbit needs to eat or drink. With higher values having litters that are larger and have shorter terms. But also require the rabbits to need to eat and drink more frequently. |
Speed | Determines how fast they can travel. With higher values resulting in faster rabbits. But it also causes them to need to eat and drink more frequently. |
Sight | Determines how far away they can see things. Such as food and other rabbits. |
Growth Rate | Determines how long it takes for a rabbit to become mature. |
When two rabbits breed the average of the parent’s traits and a random value are used to determine the traits of the children. With no limit on which rabbits can breed except for if they are old enough or not.
The user can also click on the screen and if they have the console open it will print the information on the rabbits and plants around where they clicked. The user can also hit the space bar to generate and download an image containing graphs on the about the simulation.
Example chart
The image is divided into four quadrants with 3 of which containing graphs. The lower left quadrant shows the average and max values of the four traits at any given time in the simulation. The upper left quadrant then contains the instantaneous frame rate of the simulation. Which as a result of it’s implementation also represents how fast the simulation is running. With the upper right quadrant then showing the total population at any given moment as well as population of any generation. With the generation counter in this case being passed on from the mother. This image is also automatically downloaded to the user’s computer once the simulation has reached it’s limit if there are still rabbits alive at that point. This though has been disabled on the version posted hear to avoid unwanted downloads.
Overall this was a fun and interesting project from what I remember. The only issue being that longer simulations would eventually crash. Not because of the number of rabbits but because of the generation of the graphs at the end. The method I used to generate those was by no means efficient.
I had planned a bit more for the project as well. Including implementing the rabbits actually needing to find water. As well as making it so that the plants would age, die and reproduce in a similar matter to the rabbits. But that never came to pass. So for now it stands and an interesting little side project that I did. If you want to open it in a full tab heres a link that will open it.
World Generation
Detailed 2D Height Map
The goal of this project was for me to tinker around with height map generation. With my notes indicating that I had planned on tinkering with a few different methods. With the only method I actually handled was to effectively place random pyramids on a plane and then smooth it.
But looking at the files for the project I have found that it is a better example of poor development practices rather than an example of height map generation. With a few of the most glaring examples being the file names and how it was determined what function went into which file. It is an excellent example of how I knew exactly what I was doing when I was working on the project. But coming back to it is nearly impossible due to the lack of comments or logic in how things were divided.
3D Height Map
Overall though I did get it to generate some decent results from what I can tell. And I was even able to make a 3D rendered version of it. The but it can take a not unsubstantial amount of time. With it even crashing during certain parts of the map generation. But they do work. Most of the time. If anyone is interested below are links to some functioning versions of this project. But I will say it is fully possible for them to crash.
Links
- Height from file with “random” biomes
- 3D Map Generation With Height From File
- Point of View walking of a random path. With Height from file.
- Full random map generation. Most likely to crash.
A-Star Algorithm
This project was mostly because I had wanted to learn the A* search algorithm for some reason. I honestly do not remember why I wanted to. But I have the files. Even if the implementation isn’t unique.
But in the example above the program generates a 100x100 cell map. With there being a 50/50 chance that any cell will be filled or unfilled. The path is then generated starting from the upper left. With the target being the lower right. If there is no valid path it regenerates the map and tries again.