36
3
You are given as input a greyscale image. Your task is to find a static or looping pattern in Conway's Game of Life that resembles the input image as closely as possible.
Your output can be either a still image or a looping animation in some format that can be converted to gif. The output image dimensions should be the same as the input, and it must contain only black and white pixels.
If the output is an animation, each frame must be generated from the previous one according to the Game of Life rules, with one cell per pixel. The animation must loop, with the first frame being generated from the last frame by the same rules.
If the output is a still image, applying the game-of-life rules to it must produce the same image. This means that no 'alive' cell may have more than three or less than two 'alive' neighbours, and no 'dead' cell may have exactly three 'alive' neighbours. (Note that this is basically the same as an animation as described above, but with only one frame.)
Extra rules and clarifications:
You (or your program) may choose whether 'alive' cells are represented as white and 'dead' as black, or vice versa. That is, you can either hard-code this or your program can choose it based on the input image. (But it must be the same for every frame of the animation.)
The boundary conditions should be periodic, meaning that cells on the rightmost column have neighbours on the leftmost column, etc.
For animations, the frame rate is up to you (or your program); I imagine fast frame rates will work well for approximating grey pixels.
Please post at least two results embedded in your answer. If you can post results from all of the input images below, it's preferable.
It is acceptable to scale down the test images if this is necessary in order to achieve gifs with small enough file sizes. If you want to link to larger files as well, that's fine. If you want to show off, feel free to find some higher-resolution source files.
Please try to avoid having too many controllable parameters in your code - it's best if your program's only input is the image. The exception is if you want to have a parameter for controlling the number of animation frames, since that will affect the file size.
You may use external programs to change the format of the input and output files, and/or compile output frames into an animation if you want. (This is not a file-format-handling challenge.)
This is popularity-contest, so the answer with the most votes wins.
Here is a selection of test images, mostly taken from other questions on this site. (It's possible that I will add additional "bonus" input images later.)
Just to get things started, here's a very dumb reference attempt in Python 2, which takes advantage of the fact that a block of four squares is a stable structure in the Game of Life. It just rescales the input image by a factor of 4, then draws a block if the corresponding pixel is darker than 0.5.
from skimage import io
from skimage import transform
import sys
img = io.imread(sys.argv[1],as_grey=True)
source = transform.resize(img, [i/4 for i in img.shape])
img[:]=1
for x in xrange(source.shape[0]):
for y in xrange(source.shape[1]):
if source[x,y]<0.5:
img[x*4, y*4] = 0
img[x*4+1, y*4] = 0
img[x*4, y*4+1] = 0
img[x*4+1, y*4+1] = 0
io.imsave(sys.argv[2], img)
Here are some outputs from the example code. I'm sure that much better results are possible.
I'm adding this to my list of questions to hopefully answer in the near future. – SuperJedi224 – 2015-12-01T15:49:28.257
2
Here's some high density still life segments: http://en.wikipedia.org/wiki/Still_life_(cellular_automaton)#Maximum_density. You can't get more than density 1/2 in the limit.
– xnor – 2014-10-06T05:09:59.533In your example, aren't new cells born at the junction of three squares? – xnor – 2014-10-06T08:42:34.977
@xnor oh yes, you're right. I'd better remove the example for now in that case. (I should also start writing some verification code!) – Nathaniel – 2014-10-06T08:48:50.637
@xnor I fixed it at the expense of making the image quality even worse. It's only an example after all. – Nathaniel – 2014-10-06T08:53:25.277
Fun challenge! Contestants may want to be aware of the concept of a "Garden of Eden" configuration in the Game of Life. That is, there are some configurations which cannot be generated by any predecessor state. http://en.wikipedia.org/wiki/Garden_of_Eden_(cellular_automaton)
– Abulafia – 2014-10-06T20:15:44.4073Not sure how that would help, since none of the garden of eden patterns are still lives. (which would make them their own predecessor) Similar reasoning for why they are not oscillators either. – Tally – 2014-10-06T23:24:02.940
@Tally: True, I was thinking of the garden of eden patterns as a counter-example in case someone wanted to search for predecessor-states. But I can see I was overcomplicating the approach :-) – Abulafia – 2014-10-07T18:01:58.047
BTW just how far would you allow people to scale down their images? I have an idea consisting of large amounts of gliders and reflectors to create "pixels". – Tally – 2014-10-07T22:21:48.050
@Tally it's "popularity contest", so I'll leave that up to the voters. But note that the way it's written at the moment, the output image does have to have the same dimensions as the input image, so if you use a small input image you'll have to give a small output as well. Of course there's nothing stopping you taking a large input image and then scaling out down inside your program if you want to work with bigger pixels. – Nathaniel – 2014-10-08T01:20:48.793
1
Some further inspiration for contestants: http://tlrobinson.net/blog/2009/02/game-of-life-generator/
– Abulafia – 2014-10-08T10:51:25.847