30
6
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.
You don't have a java answer yet! I'll give you one this afternoon. – SuperJedi224 – 2015-12-04T15:24:58.840
Should we assume the cells outside the image bounds are all black? – SuperJedi224 – 2015-12-04T20:45:18.107
1I think it is a duplicate - the only new parts are reading in from another file format and splitting the layers - both are basic and no challenge by themselves. – Howard – 2014-08-27T05:52:17.097
1@Howard But aren't you interested in seeing the images? – None – 2014-08-27T07:08:56.067
If you want somewhere to post pretty pictures, you could try Tumblr, Instagram, DeviantArt, ... – Peter Taylor – 2014-08-27T07:26:09.363
@PeterTaylor It seems a number of people wanted a common place to post their pretty pictures (not to mention code). God forbid we let them... – None – 2014-08-27T07:36:18.830
3
Yeah. PPCG.SE is a place of pain and agony, not fun and pretty images. If he makes the bonus idea a requirement, then surely the question must be original enough?
– Flonk – 2014-08-27T07:39:27.130@Flonk I could do that if necessary. I'd prefer not though. With the layers it would be easy and fun to identify common Life structures. The 3D wont look familiar. – None – 2014-08-27T07:45:04.513
1
@Flonk, 3D Life has been done too.
– Peter Taylor – 2014-08-27T08:09:19.0731@StandardToaster The upvotes don't necessarily mean that people disagree with Peter. I upvoted and would have close voted, too. Your idea is good (which is why it deserves an upvote) but that doesn't change the fact that it's too similar to an existing challenge and hence should be closed as a duplicate. There might even be a challenge in there somewhere if you can find an interesting CA that hasn't been done before. – Martin Ender – 2014-08-27T10:00:43.007
@Martin Upvoting duplicate questions is a bad idea, because it encourages to post more questions that are similar into already existing-one. – ST3 – 2014-08-27T14:16:34.873
@MartinBüttner Why close it precisely? I know it is a near-duplicate but so what? Surely the community's clear interest overpowers the rule. Isn't this site about enjoying programming, not the strict application of bureaucracy?? – None – 2014-08-27T19:57:13.283
@PeterTaylor I have edited the question so it is no longer a duplicate. Please reopen it. – None – 2014-08-27T21:03:11.797
3The community's clear interest is that programs not be copy-pasted with minor changes from answers to other questions. This site does not operate on the basis of "I think it might be fun, so it's ok". That's 4chan. – Peter Taylor – 2014-08-27T22:26:50.353
1@PeterTaylor "The community's clear interest is that programs not be copy-pasted with minor changes from answers to other questions." That is not all all clear to me. I think by definition the community's interest is in what they upvote. Is having two similar pieces of code on this site really some unfathomable atrocity? Either way, I have clearly edited my question such that is is not a duplicate, so I see no reason why you shouldn't rescind your close-vote. (Both being actions which I believe do operate within the basis of this site.) – None – 2014-08-27T23:19:37.747
1
If you want to argue in favour of allowing duplicates, the place to do so is http://meta.codegolf.stackexchange.com . In my opinion the change you've made is so trivial that it is still a duplicate.
– Peter Taylor – 2014-08-28T09:55:42.0301
@PeterTaylor I made a meta post in favor of allowing duplicates (though I have no stake in this particular question). Let's continue this discussion there: http://meta.codegolf.stackexchange.com/a/2108/20260
– xnor – 2014-08-28T19:20:34.0104
@Howard I don't think this counts as a duplicate anymore. Surely if http://codegolf.stackexchange.com/questions/34505/simulate-rule-110 and http://codegolf.stackexchange.com/questions/4370/simulate-any-1d-cellular-automaton?rq=1 can coexist then this is not a duplicate at all.
– Calvin's Hobbies – 2014-09-16T10:03:43.807