GithubHelp home page GithubHelp logo

peixin.io's Introduction

An aquatic ecosystem simulation game

Abstract

This project is an attempt to emulate a self-regulated aquatic ecosystem with multiple artificial populations of fish and cyanobacteria.

The movement was based on Craig Reynolds boids algorithm and is influenced by factors such as intraspecific cohesion, population direction alignment, hunger, curiosity, interspecies divergence, etc.

Reproduction, propagation, and death are all ruled by mimicking simple biological systems. That is, the death of cyanobacteria occurs in function of nutrient scarcity in the environment and by being predated by the fish, while fish death is caused only by starvation as there are no fish predators in the ecosystem up until the current state of the project.

Besides these mechanisms, there is no interspecies competition, only intraspecific, that is, the fish do not compete for food with the bacteria, only with other schools/groups of fish.

The code is in Javascript and uses the p5.js library which was fundamental to the making of the animations and graphic interface.

The build is interactive and you can try it out here!

What it does

Through keyboard inputs the user can spawn schools of fish or populations of bacteria at will, creating endless possibilities of environment creation for the beings to inhabit.

Each cyanobacteria population starts at a healthy state with 120 cells that immediately start moving and organizing themselves in a natural circular pattern to maximize cohesion. If another bacteria group is nearby it will try and get as far from it as possible to mimick the avoidance of competition for food and dispersion.

Cyanobacteria propagate in a very rapid rate. This reproduction rate depends only on the size of the group, that is, as the family gets bigger and supposedly the nutrients get less and less abundant, individual death gets more likely and propagation minimal.

Each school of fish starts healthy with moderate hunger and is populated by 30 adult fish, which will remain together and roam in search for food. If a population starts running out of food it will get desperate to find some and the adults will start to die while the school gets more and more chaotic.

When a group of fish has eaten enough for its survival it stops to go after bacteria and gets more and more stable. If a school eats more than it needs it starts to propagate, producing offspring. Newborn fish are created with a fraction of the parents size and try to stay closer to the centre of the school until they grow enough to be independent and be able to reproduce, becoming adult fish.

How the movement works

The movement of both Cyanobacteria and Fish is heavily influenced by the boids algorithm. For an explanation of the boids algorithm see: Boids Pseudocode.

Basically, each being is an object (of it's respective class) which has position and velocity as attributes. Each frame of the simulation the velocity us updated based on forces that act on each body individually, then the position is updated by adding the velocity to the previous position and just then the individual is drawn to its respective position.

The way these forces are calculated varies greatly between fish and bacteria, therefore I will be explaining them separately.

For Cyanobacteria

The bacteria movement is influenced by just three forces: cohesion, separation and divergence. Each frame these forces are updated and each works its own way.

Cohesion:

Corresponds to the vector difference between the cell and the mean position of the group. Therefore, its orientation always is pointing to the center of the group and its magnitude is proportional to the distance of the cell and the group, so farther cells feel more cohesion.

Separation:

The separation force vector is the resultant of the sum of all separation forces between a cell and each of its peers. The separation of two individual cells is calculated by getting the vector difference between them and then multiplying it by the inverse of the cube of the norm of this vector. Multiplying it once by the inverse of the norm makes it a constant unitary vector, then multiplying it by the inverse of the square of the norm makes the magnitude of the vector be inversely proportional to the square of the distance, that is, as one cell gets nearer to the other, the separation grows quadratically.

For Schools of Fish

In progress...

peixin.io's People

Contributors

heitorcoimbra avatar

Stargazers

Saulo Joab avatar Pedro Didier Maranhão avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.