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/5764116 to your computer and use it in GitHub Desktop.
Save foldi/5764116 to your computer and use it in GitHub Desktop.
FloraJS - Camera

Camera

In the above example, we have a fixed, third-person perspective of our World. But Flora can also provide a first-person perspective from the point of view of an Agent. Setting 'controlCamera' to 'true' on an agent will force Flora's camera to track that agent. Of course, there can only be one agent controlling the World's Camera.

<!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',
location: function () {
return new Burner.Vector(this.world.width * 0.25, this.world.height * 0.15);
}
});
this.add('Stimulus', {
type: 'heat',
location: function () {
return new Burner.Vector(this.world.width * 0.85, this.world.height * 0.15);
}
});
this.add('Stimulus', {
type: 'heat',
location: function () {
return new Burner.Vector(this.world.width * 0.85, this.world.height * 0.85);
}
});
this.add('Stimulus', {
type: 'heat',
location: function () {
return new Burner.Vector(this.world.width * 0.15, this.world.height * 0.75);
}
});
this.add('Stimulus', {
type: 'cold',
location: function () {
return new Burner.Vector(this.world.width * 0.5, this.world.height * 0.5);
}
});
this.add('Liquid', {
location: function () {
return new Burner.Vector(this.world.width * 0.45, this.world.height * 0.8);
}
});
this.add('Liquid', {
location: function () {
return new Burner.Vector(this.world.width * 0.65, this.world.height * 0.2);
}
});
for (var i = 0; i < 5; i ++) {
this.add('Agent', {
sensors: [
this.add('Sensor', {
type: 'heat',
behavior: 'COWARD'
}),
this.add('Sensor', {
type: 'cold',
behavior: 'ACCELERATE'
})
],
velocity: new Burner.Vector(Flora.Utils.getRandomNumber(-1, 1, true),
Flora.Utils.getRandomNumber(-1, 1, true)),
minSpeed: 1,
mass: 10,
motorSpeed: 4,
wrapWorldEdges: true,
controlCamera: !i,
color: !i ? [255, 100, 0] : [197, 177, 115]
});
}
//
this.add('Caption', {
text: 'Agent controls camera',
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,
borderWidth: 1,
borderStyle: 'dashed',
borderColor: [100, 100, 100]
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment