Skip to content

ggiuffre/conway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conway's Game of Life

Maintainability Test Coverage

A JavaScript implementation of Conway's Game of Life with a simple HTML canvas.

Preview

Check out a demo at https://ggiuffre.github.io/conway/.

Usage

Download conway.js from this repository.

Add an HTML canvas element and a script element pointing to conway.js:

<canvas id="conway">Stop using IE 8!</canvas>
<script type="text/javascript" src="conway.js"></script>

Fire up the game with this additional script:

<script type="text/javascript">
	const canvas = document.querySelector('#conway');
	const width = canvas.width = canvas.parentElement.clientWidth;
	const height = canvas.height = canvas.parentElement.clientHeight;
	const ctx = canvas.getContext('2d');
	const game = new Game(ctx, width, height);
	game.setRandomState();
	game.start();
</script>

If you don't want the game to be full-page, make sure to remove canvas.parentElement.clientWidth/Height from the script above, and set the width and height of your canvas element with CSS.