i solved the problems that i had with the last version and also implemented an algorithm that is more efficient (it calculates only the cells that have changed during the last iteration). i am glad about ideas how to further improve it (but it is also fine how it works now). hashlife?
edit: i put a second version with the name gol_v039wholegrid.pd into the zip file, which scans the whole grid every iteration instead of creating a list of the changed cells. it is faster if a lot is happening, but slower if less is happening (compared to the list version and only with large grids).
gol_v039.zip
-
Game of Life - new attempt
-
@Jona Nice work. Another interesting Cellular Automata is Wireworld. It is a 2D Turing complete Cellular Automata where you can simulate digital logic circuits. So you can build CPU's using only a few rules of Cellular Automata. Golly is a very nice tool for Cellular Automata research.
-
@Boran-Robert thanks. i will take a look into that.
-
i tried to improve the patch again (still no hashlife - not so easy for me to understand). reading lua performance tips was really helpful: https://www.lua.org/gems/sample.pdf
gol_v041.zip -
i would not say this is the last update, but from now on i will upload the changes to my github page. the main change is a new system for saving patterns. again there is a basic version and a version with glsl effects...
https://github.com/Jonathhhan/gameoflife -
here is a completely different attempt: the game of life runs on a glsl shader.
i played with that before, but i think know i understood how to customize the shader and also change the rules. it is surprisingly fast, i cannot imagine that the hashlife algorithm can be faster.
https://nullprogram.com/blog/2014/06/10/ this blog was really helpful...
a few drawbacks are that the grid is not borderless anymore (not sure how to change that in the shader),
and that it is only possible to save/copy/paste patterns that are created with mouse clicks...
and it seems difficult to grab the data from the shader for sequencing tones for example...
here is the patch: gol_shader_v001.zip
https://github.com/Jonathhhan/PDGameofLife-shaderVersion-this is the fragment shader:
uniform sampler2D Tex0; uniform vec2 resolution; uniform int lCell_1; uniform int lCell_2; uniform int lCell_3; uniform int lCell_4; uniform int lCell_5; uniform int lCell_6; uniform int lCell_7; uniform int lCell_8; uniform int dCell_1; uniform int dCell_2; uniform int dCell_3; uniform int dCell_4; uniform int dCell_5; uniform int dCell_6; uniform int dCell_7; uniform int dCell_8; int get(int x, int y) { return int(texture2D(Tex0, (gl_FragCoord.xy + vec2(x, y)) / resolution).r); } void main() { int sum = get(-1, -1) + get(-1, 0) + get(-1, 1) + get( 0, -1) + get( 0, 1) + get( 1, -1) + get( 1, 0) + get( 1, 1); int state = get(0, 0); if (sum == lCell_1 && state == 0 || sum == lCell_2 && state == 0 || sum == lCell_3 && state == 0 || sum == lCell_4 && state == 0 || sum == lCell_5 && state == 0 || sum == lCell_6 && state == 0 || sum == lCell_7 && state == 0 || sum == lCell_8 && state == 0) { gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); } else if (sum == dCell_1 && state == 1 || sum == dCell_2 && state == 1 || sum == dCell_3 && state == 1 || sum == dCell_4 && state == 1 || sum == dCell_5 && state == 1 || sum == dCell_6 && state == 1 || sum == dCell_7 && state == 1 || sum == dCell_8 && state == 1 ) { gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); } else { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); } }
also useful as a visual noise generator
-
i think i got rid of the drawbacks.
i just needed to add one line of code to make it an endless grid (took a while to find out about that...)a.fboCells:getTexture():setTextureWrap(GL_REPEAT, GL_REPEAT);
next step would be something like this (which is made with visions of chaos: https://softology.com.au/voc.htm):
-
I simplified the shader a bit (got rid of a lot of conditional logic), also the cell state is set to the alpha channel (so the color of the living cells does not matter):
// fragment shader #version 120 uniform sampler2D Tex0; uniform vec2 resolution; uniform float lCell_0; uniform float lCell_1; uniform float lCell_2; uniform float lCell_3; uniform float lCell_4; uniform float lCell_5; uniform float lCell_6; uniform float lCell_7; uniform float lCell_8; uniform float dCell_0; uniform float dCell_1; uniform float dCell_2; uniform float dCell_3; uniform float dCell_4; uniform float dCell_5; uniform float dCell_6; uniform float dCell_7; uniform float dCell_8; vec2 rule[9] = vec2[9]( vec2(lCell_0, dCell_0), vec2(lCell_1, dCell_1), vec2(lCell_2, dCell_2), vec2(lCell_3, dCell_3), vec2(lCell_4, dCell_4), vec2(lCell_5, dCell_5), vec2(lCell_6, dCell_6), vec2(lCell_7, dCell_7), vec2(lCell_8, dCell_8) ); int get(int x, int y) { return int(texture2D(Tex0, (gl_FragCoord.xy + vec2(x, y)) / resolution).a); } void main() { int sum = get(-1, -1) + get(-1, 0) + get(-1, 1) + get( 0, -1) + get( 0, 1) + get( 1, -1) + get( 1, 0) + get( 1, 1); vec2 r = rule[sum]; if (get(0, 0) == 1) { gl_FragColor = vec4(0., 0., 0., r.x); } else { gl_FragColor = vec4(0., 0., 0., r.y); } }
the current version is on my github page...
https://github.com/Jonathhhan/PDGameofLife-shaderVersion- -
i updated the patch again... "gol_shader_v006_mask" is the current version. i made a lot of changes to the render chain, because it was not working as a standalone app. it does not work, if i just bang a fbo or shader calculation (interestingly it works, if the patch runs with pure data)... my question is, how to transfer this into 3d-space with a shader (geometry shader, i think) - or a MEL script(which should be easier):
.