Created
October 29, 2023 18:28
-
-
Save iemcd/8414dca651b1d773c9c813080fac27ea to your computer and use it in GitHub Desktop.
Scripts for running Conway's Game of Life on arbitrary input images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 1. quantize input image to 3-bit colors (WRGBCMYK) | |
# 2. start the image stack | |
# 3. split into 3 channels (RGB) | |
# 4. apply 1 generation of the game of life to each channel | |
# 5. rejoin the 3 channels, append to image stack | |
# 6. loop to point 3 n times | |
# 7. output the image stack as an animated GIF | |
# 1. quantize the input image to 1-bit instead | |
# later: remap colors after | |
convert -size 21x1 xc:black -fill white \ | |
-draw 'point 3,0 point 12,0 point 13,0' \ | |
/dev/shm/life_clut.gif | |
# magick $1 -resize 480x640\> -colors 2 -colorspace Gray -ordered-dither o8x8 -normalize /dev/shm/life_loop.gif | |
magick $1 -resize 480x640\> -colors 2 -colorspace Gray -dither FloydSteiberg -normalize /dev/shm/life_loop.gif | |
for i in `seq 20`; do | |
if [ $i = 1 ]; then | |
magick /dev/shm/life_loop.gif \ | |
-write /dev/shm/life_loop.gif miff:- | |
else | |
convert /dev/shm/life_loop.gif -define convolve:scale=0.05 \ | |
-morphology Convolve '3:1,1,1 1,10,1 1,1,1' \ | |
/dev/shm/life_clut.gif -interpolate integer -clut \ | |
-write /dev/shm/life_loop.gif miff:- | |
fi | |
done | convert - -set delay 50 -layers Optimize -loop 0 life_anim.gif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 1. quantize input image to 3-bit colors (WRGBCMYK) | |
# 2. start the image stack | |
# 3. split into 3 channels (RGB) | |
# 4. apply 1 generation of the game of life to each channel | |
# 5. rejoin the 3 channels, append to image stack | |
# 6. loop to point 3 n times | |
# 7. output the image stack as an animated GIF | |
# 1. quantize the input image to 1-bit instead | |
# later: remap colors after | |
convert -size 21x1 xc:black -fill white \ | |
-draw 'point 3,0 point 12,0 point 13,0' \ | |
/dev/shm/life_clut.gif | |
# magick $1 -ordered-dither o8x8,2 /dev/shm/life_loop.gif | |
magick $1 -resize 480x620\> -dither FloydSteiberg -posterize 2 /dev/shm/life_loop.gif | |
# convert life_loop.gif -separate \ | |
# \( -clone 0 \ | |
# -define convolve:scale=0.05 \ | |
# -morphology Convolve '3:1,1,1 1,10,1 1,1,1' \ | |
# /dev/shm/life_clut.gif -interpolate integer -clut \ | |
# \) -delete 0 -insert 0 \ | |
# \( -clone 1 \ | |
# -define convolve:scale=0.05 \ | |
# -morphology Convolve '3:1,1,1 1,10,1 1,1,1' \ | |
# /dev/shm/life_clut.gif -interpolate integer -clut \ | |
# \) -delete 1 -insert 1 \ | |
# \( -clone 2 \ | |
# -define convolve:scale=0.05 \ | |
# -morphology Convolve '3:1,1,1 1,10,1 1,1,1' \ | |
# /dev/shm/life_clut.gif -interpolate integer -clut \ | |
# \) -delete 2 -insert 2 \ | |
# -combine \ | |
# life_gen_001.gif | |
for i in `seq 20`; do | |
if [ $i = 1 ]; then | |
convert /dev/shm/life_loop.gif miff:- | |
else | |
convert /dev/shm/life_loop.gif -separate \ | |
\( -clone 0 \ | |
-define convolve:scale=0.05 \ | |
-morphology Convolve '3:1,1,1 1,10,1 1,1,1' \ | |
/dev/shm/life_clut.gif -interpolate integer -clut \ | |
\) -delete 0 -insert 0 \ | |
\( -clone 1 \ | |
-define convolve:scale=0.05 \ | |
-morphology Convolve '3:1,1,1 1,10,1 1,1,1' \ | |
/dev/shm/life_clut.gif -interpolate integer -clut \ | |
\) -delete 1 -insert 1 \ | |
\( -clone 2 \ | |
-define convolve:scale=0.05 \ | |
-morphology Convolve '3:1,1,1 1,10,1 1,1,1' \ | |
/dev/shm/life_clut.gif -interpolate integer -clut \ | |
\) -delete 2 -insert 2 \ | |
-combine \ | |
-write /dev/shm/life_loop.gif miff:- | |
fi | |
done | convert - -set delay 50 -layers Optimize -loop 0 life_anim.gif | |
# One concern was the flashing and blinking of the patterns. '50' is a half-second framerate, which should be much safer. https://developer.mozilla.org/en-US/docs/Web/Accessibility/Seizure_disorders |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment