# jenova

> A game of life module that is intended to work both in a server side and client side environment.

Latest version **2.3.0** (published 2016-04-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install jenova
pnpm add jenova
yarn add jenova
bun add jenova
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.0 |
| Published | 2016-04-17 |
| First published | 2015-06-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Tyler Stark |
| Maintainers | theirondeveloper |
| Keywords | Game of Life, Conway, webpack |

## Links

- npm: https://www.npmjs.com/package/jenova
- Repository: https://github.com/TheIronDeveloper/jenova
- Issues: https://github.com/TheIronDeveloper/jenova/issues
- npm.io page: https://npm.io/package/jenova

## Dependencies (1)

- [lzutf8](https://npm.io/package/lzutf8.md) ^0.3.0

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 2.3.0 (latest) — 2016-04-17
- 2.2.0 — 2016-04-16
- 2.1.0 — 2016-03-27
- 2.0.1 — 2016-02-03
- 2.0.0 — 2016-02-03
- 0.1.1 — 2015-08-02
- 0.1.0 — 2015-07-26
- 0.0.3 — 2015-07-05
- 0.0.2 — 2015-07-01
- 0.0.1 — 2015-06-29
- 1.0.0 — 2015-06-29

## README

# Jenova ![Travis CI](https://travis-ci.org/TheIronDeveloper/jenova.svg)

A game of life module that is intended to work both in a server side and client side environment.

## Implementation

This module exposes 3 functions.

1. **compress** - Given a board array, return a compressed value and board-width
2. **expand** - Given a compressed value and width, return a board array
3. **next** - Given a board array, calculate the next "step", and return it in a callback function
4. **draw** - Given a Dom node, and some config, render a game of life board animation.

All three functions make use of an matrix consisting of 0s and 1s.

**Example Board**:

```javascript
var myBoard = [
    [0, 0, 1],
    [0, 1, 1],
    [0, 0, 0]
];

jenova.next(myBoard, {}, function(nextBoard){});

```

## Example Usage

### Browser-Only

```javascript

// Using WebPack
var jenova = require("jenova");

var initialBoard = [
	[0, 1, 0, 0, 0],
	[0, 0, 1, 1, 0],
	[0, 1, 1, 0, 0],
	[0, 0, 0, 0, 0]
];

function generateBoard(board, canvas) {

	var ctx = canvas.getContext('2d'),
		width = canvas.width,
		height = canvas.height,
		cellHeight = height/ board.length,
		cellWidth = width / board[0].length;

	// Loop through the board and draw each cell
	board.forEach(function(row, rowIndex) {
		row.forEach(function(col, colIndex) {
			ctx.fillStyle = col ? '#ccc' : '#fff';
			ctx.fillRect(colIndex*cellWidth, rowIndex*cellHeight, cellWidth, cellHeight);
			ctx.strokeRect(colIndex*cellWidth, rowIndex*cellHeight, cellWidth, cellHeight);
		});
	});

	// Finally Generate a new board, with a callback to redraw it
	jenova.next(board, {}, function(newBoard) {
		setTimeout(generateBoard.bind(this, newBoard, canvas), 200);
	});
}

window.requestAnimationFrame(generateBoard.bind(this, initialBoard, document.getElementById('myCanvas')));
```

### Server-to-Browser (using WebSockets)

**Server:**

```javascript

var initialBoard = [
	[0, 1, 0, 0, 0],
	[0, 0, 1, 1, 0],
	[0, 1, 1, 0, 0],
	[0, 0, 0, 0, 0]
];

function generateBoard(board) {
	jenova.next(board, {}, function(newBoard) {
		io.emit('newBoard', jenova.compress(newBoard));
		setTimeout(generateBoard.bind(this, newBoard), 1000);
	});
}

```

**Client:**

```javascript

var gameOfLifeCanvas = document.getElementById('gameOfLife');
var socket = io.connect('http://localhost:3000');

socket.on('newBoard', function (compressedBoard) {
	var newBoard = jenova.expand(compressedBoard.compressed, compressedBoard.width);
	generateBoard(newBoard, gameOfLifeCanvas)
});
```


## Notes

[The test cases](https://github.com/TheIronDeveloper/jenova/tree/master/test) also serve as pseudo-documentation
A websocket example can be found here: https://github.com/TheIronDeveloper/websocket-of-life

---
_Source: https://npm.io/package/jenova · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
