Skip to content

Instantly share code, notes, and snippets.

@foldi
Last active December 18, 2015 09:49
Show Gist options
  • Save foldi/5763883 to your computer and use it in GitHub Desktop.
Save foldi/5763883 to your computer and use it in GitHub Desktop.
FloraJS - Agent follows mouse

Agents

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.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>FloraJS | Simulate natural systems with JavaScript</title>
<link rel="stylesheet" href="http://www.florajs.com/demos/css/burner.min.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="http://www.florajs.com/demos/css/flora.min.css" type="text/css" charset="utf-8" />
<script src="http://www.florajs.com/demos/scripts/burner.min.js" type="text/javascript" charset="utf-8"></script>
<script src="http://www.florajs.com/demos/scripts/flora.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<script type="text/javascript" charset="utf-8">
Burner.System.init(function() {
this.add('Agent', {
followMouse: true
});
this.add('Caption', {
text: 'Agent follows mouse',
opacity: 0.4,
borderColor: 'transparent',
position: 'top center'
});
this.add('InputMenu', {
opacity: 0.4,
borderColor: 'transparent',
position: 'bottom center'
});
}, {
gravity: new Burner.Vector(),
c: 0
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment