Skip to content

Instantly share code, notes, and snippets.

@foldi
Last active December 18, 2015 09:49
Show Gist options
  • Save foldi/5764085 to your computer and use it in GitHub Desktop.
Save foldi/5764085 to your computer and use it in GitHub Desktop.
FloraJS - Sensor, Stimuli and Proximity objects

A small World

Putting it all together, we can observe Agents navigate a World with multiple Stimuli and Proximity 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,
location: function () {
return new Burner.Vector(this.world.width * 0.25, this.world.height * 0.15);
}
});
this.add('Stimulus', {
type: 'heat',
draggable: true,
location: function () {
return new Burner.Vector(this.world.width * 0.85, this.world.height * 0.15);
}
});
this.add('Stimulus', {
type: 'heat',
draggable: true,
location: function () {
return new Burner.Vector(this.world.width * 0.85, this.world.height * 0.85);
}
});
this.add('Stimulus', {
type: 'heat',
draggable: true,
location: function () {
return new Burner.Vector(this.world.width * 0.15, this.world.height * 0.75);
}
});
this.add('Stimulus', {
type: 'cold',
draggable: true,
location: function () {
return new Burner.Vector(this.world.width * 0.5, this.world.height * 0.5);
}
});
this.add('Liquid', {
draggable: true,
location: function () {
return new Burner.Vector(this.world.width * 0.45, this.world.height * 0.8);
}
});
this.add('Liquid', {
draggable: true,
location: function () {
return new Burner.Vector(this.world.width * 0.65, this.world.height * 0.2);
}
});
this.add('Agent', {
sensors: [
this.add('Sensor', {
type: 'heat',
behavior: 'COWARD'
}),
this.add('Sensor', {
type: 'cold',
behavior: 'ACCELERATE'
})
],
velocity: new Burner.Vector(1, 0.5),
minSpeed: 1,
mass: 10,
motorSpeed: 4
});
//
this.add('Caption', {
text: 'Sensor, Stimuli and Proximity Objects: Drag objects 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