Agents can carry an unlimited amount of Sensors that react to Flora's Stimulus types. The following Stimulus types are available:
- Cold
- Heat
- Food
- Light
- Oxygen
FloraJS has some built in Proximity objects that exert a force on Agents that come in direct contact or land within the object's range of influence.
In the example below, we create a Liquid object and an Agent that follows the mouse. You can click and drag to place the Liquid anywhere in the World. Use your mouse to make the Agent pass through the Liquid.
In the example below, Agents flock to the mouse. We've also adjusted the 'width' and 'height' properties.
Walkers are a step down on the evolutionary chain from Agents. They have no seeking, steering or directional behavior and just randomly explore their World. Use Walkers to create wandering objects or targets for Agents to seek.
Walkers carry two properties that directly affect how they 'walk'.
By default, Walkers use an algorithm called Perlin Noise (http://en.wikipedia.org/wiki/Perlin_noise) to navigate their World. Below is an example.
Agents are basic Flora elements that respond to forces like gravity, attraction, repulsion, etc. They can also chase after other Agents, organize with other Agents in a flocking behavior, and steer away from obstacles.
Agents are highly configurable. For a complete list of options see the docs at http://www.florajs.com/docs/symbols/Agent.html
For an example of the Agent's seek behavior, set 'followMouse' to 'true' when creating the Agent.
Every Flora system starts with one System and one World. While a System may have many Worlds, by default, Flora's system uses the <body> as the only World.
In the example above, immediately after the system starts, a Agent is created and appended to the World (or <body>).
Worlds carry two properties that directly affect their elements.
FloraJS has two major components, a set of classes for elements in a natural system, and a renderer called Burner to draw those elements to the DOM.
To setup a simple Flora system, reference the Burner and Flora .js files from scripts tag in the <head> of your document. Also, reference the Burner and Flora .css files from link tags.
In the body, add a <script> tag and create a new system. Pass the system a function that describes the elements in your world.
You should see a block fall and bounce off the bottom of your browser window.
/** | |
* Randomly reorders the contents of an array in place. | |
* @author blixt (https://github.com/blixt) | |
* @param {Array.<Object>} arr An array. | |
* @returns {Array.<Object>} The same array that was passed in, | |
* now shuffled. | |
*/ | |
function shuffleArray(arr) { | |
var i, j, item; |