Each cell in a life-like cellular automaton only needs one bit to represent it since it can only be alive or dead. That means there are only two colors; pretty boring.
Normal images have 24 bits per pixel (8 in each of R G B). This means in a normal image with pixels as cells you could simulate 24 life-like games at once!
Challenge
Your task is to write a program that will apply one generation of the rules of a life-like cellular automaton to a 24-bit depth image (in any well known format you like), and output the resulting image.
Each of the 24 layers will use the same life-like ruleset, strictly within it's own layer. The 24 layers do not interact with each other.
Also
- Zeros are dead cells and ones are live cells.
- Boundary conditions are periodic (forming a torus).
- Any image dimensions should work.
Input/Output
Your program needs to take in 3 arguments, via stdin or command line (or your language's closest equivalent):
- The name of the input image file.
- A string of the digits 0 to 8 in increasing order that denotes when new cells are born:
- If the digit d is in the string then dead cells come alive when they have d living neighbors.
- Example:
3
is normal Life - Dead cells with exactly 3 living neighbors come to life.
- A string of the digits 0 to 8 in increasing order that denotes when existing cells survive:
- If the digit d is in the string then living cells with d living neighbors survive to the next generation, otherwise they die.
- Example:
23
is normal Life - Only cells with exactly 2 or 3 neighbors survive to the next round.
Note that the Moore neighborhood is always used. Read this or this for more info on what precisely defines a life-like automaton and many interesting rulesets.
The 1-generation-later output image should either be displayed or saved as out.png
(or bmp
or whatever).
Submission
The shortest code in bytes wins.
You are required to include at least one test image and its three immediate subsequent generations for some non-trivial ruleset. Use your avatar and the normal Life rules if you can't think of anything better.
If you like you may use this Gosper Glider Gun where the only living bits are in the green 128 layer (it's only sure to work in normal Life):
Posting interesting sequences or even animations is highly encouraged.