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 20, 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
test = new Cell()
test.add_substrate( 'enzym', 1 )
test.add_substrate( 'food_out', 100 )
test.add_substrate( 'food_in', 0 )
test.add_substrate( 'transp', 0 )

Modules

  • module that creates transporters from nothing ( magix )
  • module that transports food inside the cell
  • module that breaks down food with enzym
		create_transport = new Module(
			{ rate: 2 }, 
			( t, substrates ) ->
				{ 'transp' : this.rate}
		)

		transport_food = new Module(
			{ rate: 1 },
			( t, substrates ) ->
				transporters = substrates.transp
				food_out = substrates.food_out
				transport = Math.min( transporters * this.rate, Math.max( 0, food_out ) )
				console.info substrates, transporters, food_out
				{ 
					'food_out' : -transport, 
					'food_in' : transport 
				}
		)

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

		test.add create_transport
		test.add transport_food
		test.add food_enzym
Clone this wiki locally