UNPKG

way-of-life

Version:
1 lines 4.42 kB
<!doctype html> <html lang=en> <head> <meta charset=UTF-8> <title>Way of Life</title> </head> <body> <div class=article> <canvas id=universe></canvas> <div id=fps-info></div> <section class="content text-content"> <h1>The Way of Life</h1> <p><strong>Click or touch the screen to add new cells.</strong></p> <p> The <a href=https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life>Conway's game of life</a> features an infinite grid of square cells which can be alive or dead. Each cell interacts with its eight neighbours following two rules: </p> <ol> <li>An empty cell that has exactly 3 neighbors is "born" into in the next generation.</li> <li>An occupied cell that has exactly 2 or 3 neighbors survives to the next generation. Otherwise, its occupant dies (of loneliness or overcrowding).</li> </ol> <p>There is a one line implementation of this game in <a href=https://en.wikipedia.org/wiki/APL_(programming_language)>APL</a>:</p> <p class=APL> <a href=https://dfns.dyalog.com/n_life.htm> life←{ ↑1 ⍵∨.∧3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵ } </a> </p> <p>What you are seeing is a more naïve javascript implementation of conway's game of life using an HTML canvas to draw it.</p> <p>This implementation features a universe that is a torus, ie. screen borders are connected and a cell that goes through the right border will reappear on the left one.</p> </section> <section class="content controls"> <button class="btn--raised btn--primary" id=ctrl-play-pause>Pause</button> <button class="btn--raised btn--secondary" id=ctrl-hide-show>Hide text</button> <button class="btn--raised btn--secondary" id=ctrl-engine>Use js engine</button> <br> <small>Made with ☮ by <a href=http://www.openbloc.fr>Maxime R.</a></small> </section> </div> <a href=https://github.com/blaze33/way-of-life class=github-corner aria-label="View source on Github"> <svg width=80 height=80 viewBox="0 0 250 250" aria-hidden=true> <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill=currentColor style="transform-origin:130px 106px" class=octo-arm> </path> <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill=currentColor class=octo-body> </path> </svg> </a> <a class=github-button href=https://github.com/blaze33/way-of-life data-icon=octicon-star data-size=large data-show-count=true aria-label="Star blaze33/way-of-life on GitHub">Star</a> <div class=github-link> <a href=https://github.com/blaze33/way-of-life> <svg aria-hidden=true class="octicon octicon-mark-github" height=32 version=1.1 viewBox="0 0 16 16" width=32><path fill-rule=evenodd d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg> blaze33/way-of-life </a> </div> <script async defer=defer src=https://buttons.github.io/buttons.js></script> <script>!function(e,a,t,n,g,c,o){e.GoogleAnalyticsObject=g,e.ga=e.ga||function(){(e.ga.q=e.ga.q||[]).push(arguments)},e.ga.l=1*new Date,c=a.createElement(t),o=a.getElementsByTagName(t)[0],c.async=1,c.src="https://www.google-analytics.com/analytics.js",o.parentNode.insertBefore(c,o)}(window,document,"script",0,"ga"),ga("create","UA-40941674-3","auto"),ga("send","pageview")</script> <script type="text/javascript" src="js/demo-bundle.js?9001efd7"></script></body> </html>