My Game of life program creates some cool patterns, but isnt working as i had hoped.
When i put in a glider pattern as the starting population, the patterns grow infinitely, not transitioning across screen as they should. Something must be wrong with my if statements that should control the elements 'dying.' My code is as follows:
matrix = zeros(500,500);pop =[1,1,1;1,0,0;0,1,0];matrix(250:252,250:252) = pop; %puts the initial population in the center of the matrix
while trueimshow(matrix); k = [1 1 1;1 0 1;1 1 1];neighbours = conv2(matrix, k,'same'); for row = 1:size(matrix, 1) for col = 1:size(matrix,2) if((matrix(row,col) == 1) && (neighbours(row,col)==2||3)) ||((matrix(row,col) == 0) && (neighbours(row,col)==3)) matrix(row,col) = 1; else matrix(row,col)=0; end end endend
thanks for your help
Best Answer