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

The System and its Worlds

Every Flora system starts with one System and one World. While a System may have many Worlds, by default, Flora's system uses the <body> as the only World.

In the example above, immediately after the system starts, a Agent is created and appended to the World (or <body>).

Worlds carry two properties that directly affect their elements.

  • gravity {Vector} default: new Vector(0, 1)
  • c (coefficient of friction) {number} 0.01

We can change these defaults after the system starts via the 2nd parameter to the Burner.System.init() method.

We've reversed the World's gravity and increased its friction. Now the block slowly drifts upwards.

<!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');
this.add('Caption', {
text: 'World update',
opacity: 0.4,
borderColor: 'transparent',
position: 'top center'
});
this.add('InputMenu', {
opacity: 0.4,
borderColor: 'transparent',
position: 'bottom center'
});
}, {
gravity: new Burner.Vector(0, -1),
c: 0.75
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment