Simulate Your World with Hash.ai

Simulate Your World with Hash.ai

We will admit that we often throw together software simulations of real-world things, but we’ll also admit they are usually quick and dirty and just dump out text that we might graph in a spreadsheet or using GNUPlot. But with Hash.ai, you can quickly generate simulations of just about anything quickly and easily. The simulations will have beautiful visualizations and graphs, too. The tool works with JavaScript or Python and you don’t have to waste your time writing the parts that don’t change.


The web-based tool works on the idea of agents. Each agent has one or more behaviors that run each time step. In the example simulation, which models wildfires in forests, the agent is named forest, although it really models one virtual tree. There’s also a behavior called forest which controls the tree’s rate of growth and chance of burning based on nearby trees and lightning. Other behaviors simulate a burning tree and what happens to a tree after burning — an ember — which may or may not grow back.


In that particular simulation, a call to create_scatters populates a large number of forest agents. After that, the simulation runs until you stop it. the visualization doesn’t require much work on your part other than maybe setting colors and dimensions. For example, here’s the code for an ember:



/**
* This behavior causes the agent to change from an ember
* back to a growing tree.
*/
function behavior(state, context) {
const { emberColor, emberHeight, regrowthChance } = context.globals(); // Get neighbors that are "trees"
const forestNeighbors = context.neighbors()
.filter(({behaviors}) => behaviors.includes("forest.js"));</pre>
// Turn back into a tree, with a linear increase
// in likelihood with # ..

Support the originator by clicking the read the rest link below.