Skip to content
This repository was archived by the owner on Jan 21, 2025. It is now read-only.

Module step function

Derkje-J edited this page Apr 21, 2013 · 5 revisions

A module should have a step function with this header step : ( t, substrates ) -> where t is the current time and substrates is an object with all the substrates. It should return an object with all the modified substrate deltas.

Example

Let's say you have four substrates and three modules:

Substrates

  • enzym that breaks down food
  • food outside
  • food inside
  • transporter enzym that transports food
cell = new Cell()
cell.add_substrate( 'enzym', 4 )
cell.add_substrate( 'food_out', 80 )
cell.add_substrate( 'food_in', 0 )
cell.add_substrate( 'transp', 0 )

Modules

  • module that creates transporters from food
  • module that transports food inside the cell
  • module that breaks down food with enzym
	create_transport = new Module(
		{ rate: 2 }, 
		function ( t, substrates ) {
		    create = Math.min( this.rate, substrates.food_in )
			return { 'transp' : create, 
			 'food_in' : -create }
		}
	);

	transport_food = new Module(
		{ rate: 1, osmosis: .02 },
		function ( t, substrates ) {
			transporters = substrates.transp + this.osmosis
			food_out = substrates.food_out
			transport = Math.min( transporters * this.rate, Math.max( 0, food_out ) )
			return { 
				'food_out' : -transport, 
				'food_in' : transport 
			}
		}
	);

	food_enzym = new Module(
		{},
		function ( t, substrates ) {
			food_in = substrates.food_in
			enzym = substrates.enzym
			processed = Math.min( enzym, Math.max( 0, food_in ) )
			return { 
				'food_in' : -processed 
			}
		}
	);

	cell.add( create_transport ).add( transport_food ).add( food_enzym )

	cell.visualize( 30, $('.container'), { dt: 1 } )
Clone this wiki locally