Logo Header
Life+ for WebPanOpticAverFaceLiPaSonariaRemotExam
AboutHistoryRumpelkammerDownload

Life+ for Web

♦ JavaScript snippet to display stochastic cellular automaton on a Web page, and control its behaviour ♦
♦ JavaScript-сніппет для відображення стохастичного клітинного автомата на Web-сторінці й керування його поведінкою ♦



Motivation

You've probably heard about John Conway's famous «Game of Life». If not (where have you been for the last forty years?..), then go to en.wikipedia.org/wiki/Conway's_Game_of_Life and be enlightened. Life+ is just a web-oriented probabilistic generalisation of the thing (and not a unique one, surely).

Usage

Get the snippet from Download page, rename the single .js file to «version-independent» form (say, "liferand.js") and insert the script into your web page with the following line of code:


<script src="path-to-dir-with-snippet/liferand.js" type="text/javascript"></script>


You can also stylise it by enclosing in <div style="font-family: ...; width=... "> block.

(Please do not get the script from this page, this instance has been «tuned» specifically for this page, — and not perfectly, you guess. As for the tuning, read the next section.)

Customisation

Edit the parameters in the beginning of the .js file to set field size (must be a power of 2), cell size in pixels, font sizes, colors, and so on. Don't hesitate to change other things like widths/heights anywhere in the script, if the look dosn't match your need. Well, you have the entire snippet code to tweak!

Controls

Each «Empty → Alive» slider sets the probability of any empty cell with a given number of alive neighbours (from 0 to 8) to become alive on the next turn. Likely, move «Alive → Alive» sliders to change the probabilities of alive cells with a given number of alive neighbours to stay alive.

The «Speed» slider controls the frames-per-second (or, turns-per-second) rate. In reality, it's up to what your system can handle. Since the algorithm isn't optimised much (like Hashlife or List Life for classical deterministic Life), don't expect lightspeed...

Edit

When Speed = 0 (time is stopped), you can edit the field per-cell: click on the cell to switch its state (empty one becomes alive, and vice versa). When Speed > 0, a single click anywhere on the field clears it, and double click fills it with random pattern.

Coloring

Color reflects the age of alive cell, in «logarithmic-rainbow» scale: the new-born cell is violet, the cell which lived from 1 to 2 turns is blue, which lived from 2 to 4 turns is light-blue, which has been alive for 4–8 turns is cyan etc. Empty cells are black.

Copyright © 2014–2023 Sunkware
Style:  NightWinterSea
VisitIPs is 👁watching👁 you⟩