Giter VIP home page Giter VIP logo

terra's Introduction

terra

JS library for cellular automata and simple biological simulations. Documentation and examples live here.

Hacking this library

To build terra on your machine you'll need Node.js, Bower, and gulp installed. Then...

cd path/to/terra
npm install
bower install
gulp

Contributing

At this stage the most important way you can help is to use the library. The API is in Beta and still flexible. If you discover something that's confusing or hard to work with, document it here. Come up with an idea and try to build it; by using and testing the library you'll find bugs or usability issues that would otherwise go unnoticed. If you want to make a pull-request on anything labeled 'major', be sure to join the discussion first so we can talk architecture. If anyone's willing to get the ball rolling on unit tests, you will be my hero.

That's all, folks! MIT, remixing strongly encouraged.

terra's People

Contributors

johnhenry avatar rileyjshaw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terra's Issues

Cannot find 'demo' module

I want to try this out but when I follow the directions:

cd /path/to/terra
npm install
gulp

I get an error message:

$ gulp
[18:11:20] Using gulpfile ~/Projects/terra/gulpfile.js
[18:11:20] Starting 'lint'...
[18:11:20] Starting 'demo'...
[18:11:20] Starting 'sass'...
[18:11:20] Starting 'webserver'...
[18:11:20] Webserver started at http://0.0.0.0:8000
[18:11:20] Finished 'webserver' after 5.3 ms
[18:11:20] Starting 'watch'...
[18:11:20] Finished 'watch' after 13 ms
[18:11:20] Finished 'sass' after 39 ms
[18:11:20] Starting 'css_concat'...
[18:11:20] Finished 'css_concat' after 12 ms

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: Cannot find module './demo/scripts/main.js' from '/Users/dylntrnr/Projects/terra'
    at /Users/dylntrnr/Projects/terra/node_modules/browserify/node_modules/resolve/lib/async.js:42:25
    at load (/Users/dylntrnr/Projects/terra/node_modules/browserify/node_modules/resolve/lib/async.js:60:43)
    at /Users/dylntrnr/Projects/terra/node_modules/browserify/node_modules/resolve/lib/async.js:66:22
    at /Users/dylntrnr/Projects/terra/node_modules/browserify/node_modules/resolve/lib/async.js:21:47
    at Object.oncomplete (fs.js:107:15)

I think this is because in your .gitignore file you are ignoring the demo directory.

Add neighborhood options

Add a simpler method to choose between Moore and Von Neumann neighborhoods.

var t = new terra.Terrarium(4, 4, {
  neighborhood: 'vonNeumann'
});

A Von Neumann neighborhood can be achieved in the interim (or on a per-creature basis) by simply filtering the Moore neighbors in process().

Suggested by @crawfy48.

Allow a user-definable stopping condition

Allow a comparison function to run on a per-creature-per-n-steps basis (where n is a definable resolution). For speed reasons it probably doesn't make sense to allow for "compare with last creature that was here" type checks..

// animate until all creatures of type 'important' are dead
...animateWithStoppingCondition(function (creature) {
  // if any creatures return `true`, continue the simulation
  return creature.type === 'important';
});

Can't get an example to work.

I'm using the following code, no errors, getting a 0x0 canvas with nothing displayed. If I manually increase the size of the canvas with the inspector I get a green square. Any ideas?

<html>
<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="terra.js"></script>
</head>
<body>
<script type="text/javascript">
  $().ready(function() {
// the demo running at the top of this page
var paTerrarium = new terra.Terrarium(25, 25);

terra.creatureFactory.register({
  type: 'plant',
  color: [0, 120, 0],
  size: 10,
  initialEnergy: 5,
  maxEnergy: 20,
  wait: function() {
    // photosynthesis :)
    this.energy += 1;
  },
  move: false,
  reproduceLv: 0.65
});

terra.creatureFactory.register({
  type: 'brute',
  color: [0, 255, 255],
  maxEnergy: 50,
  initialEnergy: 10,
  size: 20
});

terra.creatureFactory.register({
  type: 'bully',
  color: [241, 196, 15],
  initialEnergy: 20,
  reproduceLv: 0.6,
  sustainability: 3
});

paTerrarium.populate([['plant', 50], ['brute', 5], ['bully', 5]]);
paTerrarium.animate();
});
</script>
</body>

</html>

CAs: Adding interactive functions via HTML buttons

Heya,

Using terra.js, I just made a simple predator prey CA that results in traveling/chaotic waves:

http://theoreticalbiology.nl/spiders/

I'm looking to extend this by allowing interactive functions, such as killing some prey, killing some predators, restarting, etc. The default terrarium functions .animate() and .stop() function propperly. How can I add new functions to this terrarium?

I tried figuring out how to do this in the terra.js module, which sort of worked, but I'm looking for advice on how to do this "neatly" in javascript.

UPDATE: i've mostly overwritten the old version, so most of the functionality I discuss here is now implemented.

Bram

Set frame rate/ animation delay

By default the animation is synced to the frame rate of the monitor. It would be nice if a custom frame rate or a delay (e.g. 1 second between frames) could be set before calling animate(). I'd be happy to look into doing this for you.

Remove global override of Math.random

Early on, I decided to use seedrandom's { global: true } option. It was a silly decision in retrospect.

The big change here is that seedrandom should be internal to terra and not pollute Math.random().

Following this thread, seeded RNG should really be handled more granularly anyway. Initial thoughts:

  1. Each terrarium is given a unique ID
  2. This ID is used to seed the terrarium's RNG

That way, a terrarium recipe and ID are all you need to perfectly reproduce a simulation. It'll no-longer be bound to other uses of random() on the page.

Thanks @benswinden for the heads up! 👍

Oh, Canada!

Alias colourto color, neighbourhood to neighborhood, etc.

Add unit tests

This is a pretty important one... anyone want to join forces?

Debug information while making stuff in terra

Hi !

Background

I was going through your introduction over at http://rileyjshaw.com/terra and I got stumped by the following not working as demonstrated:

screen shot 2015-03-13 at 13 11 14

Initially I thought the frequency of frames was too high so I set about counting the number of Ticks:
screen shot 2015-03-13 at 13 13 58

It turned out only 8 ticks were happening.
-- At this point I realised the creature 'Plant' from the first screenshot was not initialised.

So, my suggestion is:

Lets have some debug info available in terra from dev tools!

One I have added in for myself is 'registeredCreatures':
screen shot 2015-03-13 at 13 20 18

Note

I'm a noob, please excuse me if I missed an existing way of getting this information.

Allow periodic boundaries

Currently, corner cells have 3 adjacent cells and wall cells have 5. Periodic boundary conditions would allow every cell to have 8 adjacent cells by "wrapping around" the Terrarium.

var t = new terra.Terrarium(4, 4, {
  boundary: 'periodic'
});

Suggested by @crawfy48.

registerCreature and registerCA should be separate functions

This comment exposes some flaws in trying to squeeze creatures and CAs into the same class.

Proposal:

// internal
terra.factory.registerCreature = function () { //... };
terra.factory.registerCA = function () { //... };

// API
terra.registerCreature = function (args..) {
  return terra.factory.registerCreature(args..);
};
terra.registerCA = function (args..) {
  return terra.factory.registerCA(args..);
};

terra.factory.make() can still produce creatures and CAs.

Affects Math.random()

Loaded up terra via <script> tags (to try it out and test if it fits my project).
I have Math.random()'s in my script– with terra loaded, I get a constant value from Math.random every single time/refresh console.log(Math.random())

Removed the script, and worked fine again. Haven't looked into it in depth exactly why this is happening with terra, but just putting it out there

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.