Skip to content

Instantly share code, notes, and snippets.

@foldi
Last active December 18, 2015 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foldi/5764066 to your computer and use it in GitHub Desktop.
Save foldi/5764066 to your computer and use it in GitHub Desktop.
FloraJS - Sensor + Stimulus

Sensors and Stimuli

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

Sensors are tuned specifically to a Stimulant and can be configured to activate a specific behavior. The following behaviors are available:

  • ACCELERATE
  • DECELERATE
  • AGGRESSIVE
  • COWARD
  • LIKES
  • LOVES
  • EXPLORER

In the example below, the Agent carries a Sensor that senses Heat. When activated, it triggers the 'COWARD' behavior.

Notice, we've updated the World and removed any gravitational forces. We've also updated the 'motorSpeed' property to give the Agent a constant velocity. You should see the Agent navigate the World and avoid the Heat objects.

<!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('Stimulus', {
type: 'heat',
draggable: true
});
this.add('Agent', {
sensors: [
this.add('Sensor', {
type: 'heat',
behavior: 'COWARD'
})
],
velocity: new Burner.Vector(1, 0.5),
maxSpeed: 5,
motorSpeed: 10
});
//
this.add('Caption', {
text: 'Sensor + Stimulus: Drag the Heat into the Agent\'s path',
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