zasim.cagen.utils - Utility functions

zasim.cagen.utils.offset_pos(pos, offset)[source]

Offset a position by an offset. Any amount of dimensions should work.

>>> offset_pos((1, ), (5, ))
(6,)
>>> offset_pos((1, 2, 3), (9, 8, 7))
(10, 10, 10)
zasim.cagen.utils.gen_offset_pos(pos, offset)[source]

Generate code to offset a position by an offset.

>>> gen_offset_pos(["i", "j"], ["foo", "bar"])
['i + foo', 'j + bar']
zasim.cagen.utils.dedent_python_code(code)[source]

Dedent a bit of python code, like this:

>>> print dedent_python_code("""# update the histogram
...     if result != center:
...         self.target.histogram[result] += 1""")
# update the histogram
if result != center:
    self.target.histogram[result] += 1
zasim.cagen.utils.rule_nr_to_multidim_rule_arr(number, digits, base=2)[source]

Given the rule number, the number of cells the neighbourhood has (as digits) and the base of the cells, this function calculates the multidimensional rule table for computing that rule.

zasim.cagen.utils.rule_nr_to_rule_arr(number, digits, base=2)[source]

Given a rule number, the number of cells the neighbourhood has (as digits) and the base of the cells, this function calculates the lookup array for computing that rule.

>>> rule_nr_to_rule_arr(110, 3)
[0, 1, 1, 1, 0, 1, 1, 0]
>>> rule_nr_to_rule_arr(26, 3, 3)
[2, 2, 2, ...]
zasim.cagen.utils.elementary_digits_and_values(neighbourhood, base=2, rule_arr=None)[source]

From a neighbourhood, the base of the values used and the array that holds the results for each combination of neighbourhood values, create a list of dictionaries with the neighbourhood values paired with their result_value ordered by the position like in the rule array.

If the rule_arr is None, no result_value field will be generated.

Previous topic

zasim.cagen.simulators - Simulators immediately ready to be used

Next topic

zasim.gui - Qt based display and user interface

This Page