Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

space-colonization

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

space-colonization

space colonization algorithm

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

space-colonization

unstable

alt text

Algorithm for tree-like and bush-like objects. Based on this paper.

Usage

$ npm i -S space-colonization

iterate = space-colonization(opts)

Options:

  • buds: array of buds position in the format [x, y, z]. This is where your tree is going to grow from
  • hormones: array of hormones (aka attractors) in the format [x, y, z]. Read the paper for more info on what they are. But simply put, they attract the branch to grow towards them. Can be randomly generated, for more sophisticated type of trees you can generate points inside a crown-like shape. More examples on how to do this will be added soon.
  • deadZone: the radius of which hormones are killed after each iteration. read the paper for more info. defaults to 0.1
  • growthStep: how far a branch can jump on each iteration. defaults to 0.3
  • splitChance: how likely it is to split on each iteration. defaults to 0.4
  • viewAngle: the angle at which an alive bud (the tip of a growing branch) can see hormones. defaults to 30 (measured in degrees)
  • viewDistance: how far the alive bud can see hormones. defaults to 0.5
  • branchAngle: when a split happens, how far the two new branches bend away from each other. defaults to 30 (measured in degrees)
  • straightSplit: if true, only new branch bends to the branchAngle. if false, both old and new branches bend (i. e. you get a V-like shape)

These numbers (except the angles) assume the buds and hormones have a distance between them in the same range (e.g. from 0 to 5). If you provide positions that have a range of 10-50 for example nothing will grow because the viewDistance is too small for the initial bud to see anything!

When you call the above function you get back an iterate function. This function can be called every frame to grow the tree until all hormones are dead or all buds die before they eat all possible hormones. The result of each call is an object with two properties:

  • buds: an array of buds with each bud an object with properties:
    • state: 0 for alive, 1 for dead
    • position: [x, y, z]
    • parentIndex: the index of the parent bud in the buds array. -1 if no parent
  • hormones: an array of hormones with each hormone an object with two properties:
    • state: 0 for alive, 1 for dead
    • position: [x, y, z]

More info and examples will be coming soon. Post an issue if anything is unclear. See example.js for basic usage with regl.

License

MIT

FAQs

Package last updated on 14 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc