%%%% Conway's Game of Life. For MATLAB Seminar. James Ryan 2024

function conway(image_path)
	if (~exist('image_path', 'var'))
		close all; clear; clc;
		imageIn = randi([0 1], 480, 640);
   	else % image path specified (eg: `conway("zaza.jpeg")`)
		imageIn = importdata(image_path);
		imageIn = 0.2989*imageIn(:,:,1) ...
		      + 0.5870*imageIn(:,:,2) ...
		      + 0.1140*imageIn(:,:,3);
		
		imageMean = cast(mean(imageIn),"uint8");
		imageIn = ~(clip(imageIn, imageMean - 1, ... 
		                          imageMean));
	end

	[imageLong imageLat] = size(imageIn);

	board = imshow(imageIn, InitialMagnification=imageLong);
	pause(0.25);
	% Run conways!
	while true
		pause(0.5);
		board.CData = update(board.CData);
		drawnow;
	end
end
