Inspiration:
The inspiration for this project was the concept of an ecosystem simulation. The idea was to create a dynamic environment where different entities interact with each other and evolve. The entities in this ecosystem are Boids, Pacmen, and Ghosts, each with their own behaviors and attributes. The user can be the decider of how these creatures evolve by adjusting these attributes using sliders.
Why Pacman?
The Pacman theme was chosen for this project due to its familiarity, aesthetics, and game dynamics. It’s a well-known game, making the ecosystem simulation easy to understand. The bright colors and simple shapes enhance the user experience, and the game’s chase and evade mechanics effectively illustrate predator-prey relationships in nature.
First Iteration:
The first iteration of the project involved setting up the basic structure of the ecosystem. These vehicles exhibit behaviors similar to those of living organisms, such as seeking food, avoiding poison, and reproducing. The main idea is to create a basic system that I can build on top of for my next iteration. I set up the foundational functions, such as seeking and reproduction.
Next Steps:
Fleeing Behavior: Fleeing behavior for the boids was added, which is triggered when a predator or apex predator is nearby. This made the simulation more realistic and dynamic.
Introduction of Apex Predators: Apex predators were introduced into the ecosystem. These entities hunt both boids and predators, adding another layer of complexity to the simulation.
User Controls Added: More user controls were added to the simulation. This included sliders to adjust the speed, reproduction rate, and lifespan of each entity type. This allows users to experiment with different settings and observe how they affect the ecosystem.
Pacman Theme: The visuals of the simulation were improved by using images instead of simple shapes for the entities. This made the simulation more visually appealing and engaging.
Performance Optimized: As the complexity of the simulation increased, the code was optimized to ensure that it ran smoothly. This involved techniques such as quadtree optimization for collision detection
Code that I am proud of:
seek(target) { let desired = p5.Vector.sub(target, this.position); desired.setMag(this.maxSpeed); let steer = p5.Vector.sub(desired, this.velocity); steer.limit(this.maxForce); this.applyForce(steer); }
The seek() function in the ApexPredator class is used to move the apex predator towards a target. It calculates a desired velocity vector pointing from the apex predator to the target, sets its magnitude to the maximum speed of the apex predator, and then calculates a steering force to apply to the apex predator to move it towards the target.
flee(target) { let desired = p5.Vector.sub(this.position, target); desired.setMag(this.maxSpeed); let steer = p5.Vector.sub(desired, this.velocity); steer.limit(this.maxForce); this.applyForce(steer); }
The flee() function in the Boid class is used to move the boid away from a target. It calculates a desired velocity vector pointing from the target to the boid, sets its magnitude to the maximum speed of the boid, and then calculates a steering force to apply to the boid to move it away from the target.
function changePlaySpeed(){ if (playSpeed === 1) { playSpeed = 2; } else if (playSpeed === 2) { playSpeed = 4; } else if (playSpeed === 4) { playSpeed = 8; } else if (playSpeed === 8) { playSpeed = 1; } playSpeedButton.html('Play Speed:' + playSpeed + 'x'); }
The changePlaySpeed() function is used to cycle through different play speeds each time it is called. The play speed is displayed on a button in the user interface.
Challenges:
Autonomous Agent Logic
Implementing autonomous agent logic was a significant challenge. This involved creating behaviors for the boids, pacmen, and ghosts in the ecosystem. Each entity needed to have its own set of behaviors and interactions with other entities, which required a deep understanding of vectors, forces, and steering behaviors.
Slider Range Balancing
Balancing the range of the sliders was another challenge. The sliders control various attributes of the entities, such as speed, force, and reproduction rate. Finding a range that provided meaningful changes without causing extreme behaviors was a delicate balancing act.
Performance Management
Managing performance was a critical challenge. With potentially hundreds of entities on the screen at once, each with its own set of behaviors and interactions, the simulation could easily become slow and unresponsive. Optimizing the code to handle this complexity while still running smoothly was a significant part of the project.
Final Touches:
The final steps of the project involved refining the behaviors of the entities and improving the user interface. This included adding a button for generating the next generation of entities, and creating a screen for displaying the sliders that control the attributes of the entities.
Final Sketch:
Possible Future Improvements:
– Adding more entity types: The ecosystem could be made even more complex and interesting by adding more types of entities, such as plants or other types of animals.
– Implementing genetic algorithms: The entities could be made to evolve over time using genetic algorithms, with the most successful entities passing on their traits to the next generation.
-Special Creature Abilities: A possible improvement could be adding new abilities that the creatures can occasionally use to grow their numbers and recover from the brink of extinction.
IM Showcase:
The IM showcase was a success, and many people were stopping by to check out the class’s projects. The learning curve on the simulation was quite high for visitors and it took a while for them to get the hang of the game.
I also decided to showcase my midterm project, which actually caught the eyes of more people because it was more visually interesting.
Final Thoughts:
The journey of this project, from its initial conception to its final iteration, has been a testament to the iterative nature of design. It presented several challenges, but also provided the opportunity to learn and apply new concepts. The end result is a dynamic ecosystem simulation that is visually interesting to interact with. I still think however there is a lot more room for improvements in the future which I would like to explore.