Skip to content

Instantly share code, notes, and snippets.

@Alexei-B
Forked from aemkei/LICENSE.txt
Last active January 9, 2016 16:41
Show Gist options
  • Select an option

  • Save Alexei-B/aee3708a7d8280b33ed2 to your computer and use it in GitHub Desktop.

Select an option

Save Alexei-B/aee3708a7d8280b33ed2 to your computer and use it in GitHub Desktop.

Revisions

  1. Alexei Barnes revised this gist Jan 9, 2016. 4 changed files with 5 additions and 6 deletions.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Game of Life - 140byt.es

    An implementation of Conway's [Game of Life](http://en.wikipedia.org/wiki/Conway's_Game_of_Life) in only 92 bytes of JavaScript.
    An implementation of Conway's [Game of Life](http://en.wikipedia.org/wiki/Conway's_Game_of_Life) in only 90 bytes of JavaScript.

    See the demo: http://output.jsbin.com/zebuxi

    5 changes: 2 additions & 3 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    b, // array to fill with new state
    c, // width of stage
    d // placeholder
    )=>{
    )=> // No {} braces are nessessary due to single statement.
    a.map( // Map this function over the whole old state.
    (
    e, // placeholder
    @@ -27,5 +27,4 @@
    )*c - c // and scale to width.
    ]
    }
    )
    }
    )
    2 changes: 1 addition & 1 deletion index.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    (a,b,c,d)=>{a.map((e,f)=>{for(d=9,e=0;d--;b[f]=e==3|e==4&a[f])e+=~~a[f+d%3-1+~~(d/3)*c-c]})}
    (a,b,c,d)=>a.map((e,f)=>{for(d=9,e=0;d--;b[f]=e==3|e==4&a[f])e+=~~a[f+d%3-1+~~(d/3)*c-c]})
    2 changes: 1 addition & 1 deletion test.html
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@
    <div id="stage"></div>

    <script>
    var game = (a,b,c,d)=>{a.map((e,f)=>{for(d=9,e=0;d--;b[f]=e==3|e==4&a[f])e+=~~a[f+d%3-1+~~(d/3)*c-c]})};
    var game = (a,b,c,d)=>a.map((e,f)=>{for(d=9,e=0;d--;b[f]=e==3|e==4&a[f])e+=~~a[f+d%3-1+~~(d/3)*c-c]});

    var width = 32;
    var height = 32;
  2. Alexei Barnes revised this gist Aug 12, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -17,8 +17,8 @@ Usage
    Author
    ------

    Originally Created by Martin Kleppe ([@aemkei](http://twitter.com/aemkei)) at [Ubilabs](http://ubilabs.net/).
    New Version Created by Alexei Barnes ([@Alexei_Barnes](https://twitter.com/Alexei_Barnes)) at [AlexeiBarnes.com](http://alexeibarnes.com).
    * Originally Created by Martin Kleppe ([@aemkei](http://twitter.com/aemkei)) at [Ubilabs](http://ubilabs.net/).
    * New Version Created by Alexei Barnes ([@Alexei_Barnes](https://twitter.com/Alexei_Barnes)) at [AlexeiBarnes.com](http://alexeibarnes.com).

    For more information
    --------------------
  3. Alexei Barnes revised this gist Aug 12, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Game of Life - 140byt.es

    An implementation of Conway's [Game of Life](http://en.wikipedia.org/wiki/Conway's_Game_of_Life) in less than 140 bytes of JavaScript.
    An implementation of Conway's [Game of Life](http://en.wikipedia.org/wiki/Conway's_Game_of_Life) in only 92 bytes of JavaScript.

    See the demo: http://output.jsbin.com/zebuxi

  4. Alexei Barnes revised this gist Aug 12, 2015. 6 changed files with 83 additions and 66 deletions.
    2 changes: 1 addition & 1 deletion LICENSE.txt
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
    Version 2, December 2004

    Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
    Copyright (C) 2015 Alexei Barnes <http://alexeibarnes.com>

    Everyone is permitted to copy and distribute verbatim or modified
    copies of this license document, and changing it is allowed as long
    12 changes: 6 additions & 6 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,23 +2,23 @@

    An implementation of Conway's [Game of Life](http://en.wikipedia.org/wiki/Conway's_Game_of_Life) in less than 140 bytes of JavaScript.

    See the demo: http://jsfiddle.net/aemkei/wdRcc/show/
    See the demo: http://output.jsbin.com/zebuxi

    Usage
    -----

    life (
    input, // input array
    size // size (width and height) of stage
    input, // input array
    target, // target array
    width // width of stage
    )

    // returns the modificated input string


    Author
    ------

    Created by Martin Kleppe ([@aemkei](http://twitter.com/aemkei)) at [Ubilabs](http://ubilabs.net/).
    Originally Created by Martin Kleppe ([@aemkei](http://twitter.com/aemkei)) at [Ubilabs](http://ubilabs.net/).
    New Version Created by Alexei Barnes ([@Alexei_Barnes](https://twitter.com/Alexei_Barnes)) at [AlexeiBarnes.com](http://alexeibarnes.com).

    For more information
    --------------------
    53 changes: 30 additions & 23 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,31 @@
    life = function(
    input, // input array
    size, // square stage size (width and height)
    output, i, neighbours // placeholders
    ){
    // cycle through cells
    for (
    output = [i = size*size];
    i--;
    output[i] =
    // alive if it has 3 neighbours
    neighbours == 3 ||
    // stay alive if cell has 2 neighbours
    (input[i] && neighbours == 2)
    ) {
    neighbours =
    // count neighbours
    input[i-size-1] + input[i-size] + input[i-size+1] +
    input[i -1] + input[i +1] +
    input[i+size-1] + input[i+size] + input[i+size+1];
    }

    return output;
    ( // Using ECMA6 arrow functions. IE, Safari & Opera probably won't work.
    a, // array of old state
    b, // array to fill with new state
    c, // width of stage
    d // placeholder
    )=>{
    a.map( // Map this function over the whole old state.
    (
    e, // placeholder
    f // linear index of cell
    )=>{
    for(
    d = 9, // Start our neighborhood walk at 9.
    e = 0; // Start sum of neighbors at 0.
    d--; // Walk backwards until and including 0.
    b[f] = // Set cell after loop execution (only the last loop matters).
    e == 3 | // The sum includes self so the rules change a bit, any rusult of 3 or,
    e == 4 & // a result of 4 and,
    a[f] // self is true results in an alive cell, otherwise dead.
    )
    e += // each loop accumulate to sum
    ~~a[ // Index old state and return 0 if undefined.
    f + // Index plus,
    d%3 - 1 + // convert linear walk value to horizontal component plus,
    ~~( // round down,
    d/3 // walk converted to vertical component,
    )*c - c // and scale to width.
    ]
    }
    )
    }
    2 changes: 1 addition & 1 deletion index.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    function(a,b,c,d,e){for(c=[d=b*b];d--;c[d]=e==3||a[d]&&e==2)e=a[d-b-1]+a[d-b]+a[d-b+1]+a[d-1]+a[d+1]+a[d+b-1]+a[d+b]+a[d+b+1];return c}
    (a,b,c,d)=>{a.map((e,f)=>{for(d=9,e=0;d--;b[f]=e==3|e==4&a[f])e+=~~a[f+d%3-1+~~(d/3)*c-c]})}
    4 changes: 2 additions & 2 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    {
    "name": "gameOfLife",

    "description": "Implementation of Conway's Game of Live.",
    "description": "Even Smaller ECMA6 Implementation of Conway's Game of Live.",

    "keywords": [
    "conway",
    "ecma6",
    "game",
    "life",
    "cellular",
    76 changes: 43 additions & 33 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@

    <style type="text/css" media="screen">
    #stage {
    display: inline-block;
    line-height:12px;
    }

    @@ -24,41 +25,50 @@
    <body>
    <div id="stage"></div>

    <a href="https://gist.github.com/1134658">Source</a>
    <script src="annotated.js" type="text/javascript" charset="utf-8"></script>


    <script>
    var array = [],
    elems = {},
    elem,
    stage = document.getElementById("stage"),
    size = 50,
    x, y;

    // create DOM elements
    for (x = 0; x < size; x++){
    for (y = 0; y < size; y++){
    elem = document.createElement("div");
    stage.appendChild(elem);
    elems[x + "," + y] = elem;
    array.push(Math.random() < 0.5);
    }
    stage.appendChild(document.createElement("br"));
    }
    <script>
    var game = (a,b,c,d)=>{a.map((e,f)=>{for(d=9,e=0;d--;b[f]=e==3|e==4&a[f])e+=~~a[f+d%3-1+~~(d/3)*c-c]})};

    // render stage
    function play(){
    var index = 0, color;

    array = life(array, size);
    for (x = 0; x < size; x++){
    for (y = 0; y < size; y++){
    elems[x + "," + y].className = array[index++] ? "alive" : "";
    var width = 32;
    var height = 32;
    var fields = [new Array(width * height), new Array(width * height)];
    var elems = [];
    var target = 0;
    var stage;

    function init() {
    stage = document.getElementById("stage");
    for (var y = 0; y < height; ++y) {
    for (var x = 0; x < width; ++x) {
    elems[elems.length] = document.createElement("div");
    stage.appendChild(elems[elems.length - 1]);
    }
    stage.appendChild(document.createElement("br"));
    }
    }
    setTimeout(play, 10);

    fields[0].fill(0);
    fields[1].fill(0);

    setInterval(run, 50);

    document.addEventListener('mousemove', brush, true);
    }
    play();

    function run() {
    for (var i = 0; i < width * height; ++i) elems[i].className = fields[target][i] ? "alive" : "";

    game(fields[target], fields[1 - target], width);
    target = 1 - target;
    }

    function brush(e) {
    var rect = stage.getBoundingClientRect();
    var x = Math.floor((e.clientX - rect.left) / (rect.width / width));
    var y = Math.floor((e.clientY - rect.top) / (rect.height / height));

    if (x >= 0 && y >= 0 && x < width && y < height)
    fields[target][x + y * width] = 1;
    }

    init();
    </script>
    </body>
  5. @aemkei aemkei revised this gist Feb 14, 2012. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    Game of Life - 140byt.es
    ========================
    # Game of Life - 140byt.es

    An implementation of Conway's [Game of Life](http://en.wikipedia.org/wiki/Conway's_Game_of_Life) in less than 140 bytes of JavaScript.

  6. @aemkei aemkei revised this gist Dec 1, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ Game of Life - 140byt.es

    An implementation of Conway's [Game of Life](http://en.wikipedia.org/wiki/Conway's_Game_of_Life) in less than 140 bytes of JavaScript.

    See the example: [http://www.ubilabs.net/projects/game-of-life](http://www.ubilabs.net/projects/game-of-life)
    See the demo: http://jsfiddle.net/aemkei/wdRcc/show/

    Usage
    -----
  7. @aemkei aemkei revised this gist Oct 4, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ Game of Life - 140byt.es

    An implementation of Conway's [Game of Life](http://en.wikipedia.org/wiki/Conway's_Game_of_Life) in less than 140 bytes of JavaScript.

    See the example: [ubilabs.net/projects/game-of-live](http://www.ubilabs.net/projects/game-of-live)
    See the example: [http://www.ubilabs.net/projects/game-of-life](http://www.ubilabs.net/projects/game-of-life)

    Usage
    -----
  8. @aemkei aemkei revised this gist Aug 15, 2011. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,16 @@
    life = function(
    input, // input array
    size, // size (width and height) of stage
    size, // square stage size (width and height)
    output, i, neighbours // placeholders
    ){
    // cycle through cells
    for (
    output=[i=size*size];
    output = [i = size*size];
    i--;
    output[i] =
    // live if it has 3 neighbours
    // alive if it has 3 neighbours
    neighbours == 3 ||
    // stay alive if it has 2 neighbours
    // stay alive if cell has 2 neighbours
    (input[i] && neighbours == 2)
    ) {
    neighbours =
  9. @aemkei aemkei revised this gist Aug 15, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    life = function(
    input, // input array
    size, // size (width and height) of stage
    output, i, neighbourspush // placeholders
    output, i, neighbours // placeholders
    ){
    // cycle through cells
    for (
  10. @aemkei aemkei revised this gist Aug 15, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    life = function(
    input, // input array
    size, // size (width and height) of stage
    output, i, neighbours, length // placeholders
    output, i, neighbourspush // placeholders
    ){
    // cycle through cells
    for (
    output=[length=i=size*size];
    output=[i=size*size];
    i--;
    output[i] =
    // live if it has 3 neighbours
  11. @aemkei aemkei revised this gist Aug 15, 2011. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    live = function(
    life = function(
    input, // input array
    size, // size (width and height) of stage
    output, i, neighbours // placeholders
    output, i, neighbours, length // placeholders
    ){
    // cycle through cells
    for (
    output=[i=size*size];
    output=[length=i=size*size];
    i--;
    output[i] =
    // live if it has 3 neighbours
  12. @aemkei aemkei revised this gist Aug 15, 2011. 3 changed files with 15 additions and 12 deletions.
    19 changes: 10 additions & 9 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,23 @@
    function(
    live = function(
    input, // input array
    size, // size (width and height) of stage
    output, i, neighbours // placeholders
    ){
    // cycle through cells
    for (i = output = []; ++i < size*size;) {

    for (
    output=[i=size*size];
    i--;
    output[i] =
    // live if it has 3 neighbours
    neighbours == 3 ||
    // stay alive if it has 2 neighbours
    (input[i] && neighbours == 2)
    ) {
    neighbours =
    // count neighbours
    input[i-size-1] + input[i-size] + input[i-size+1] +
    input[i -1] + input[i +1] +
    input[i+size-1] + input[i+size] + input[i+size+1];

    output[i] =
    // live if it has 3 neighbours
    neighbours == 3 ||
    // stay alive if it has 2 neighbours
    (input[i] && neighbours == 2);
    }

    return output;
    2 changes: 1 addition & 1 deletion index.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    function (a,b,c,d,e){for(d=c=[];d++<b*b;)e=a[d-b-1]+a[d-b]+a[d-b+1]+a[d-1]+a[d+1]+a[d+b-1]+a[d+b]+a[d+b+1],c[d]=e==3||a[d]&&e==2;return c}
    function(a,b,c,d,e){for(c=[d=b*b];d--;c[d]=e==3||a[d]&&e==2)e=a[d-b-1]+a[d-b]+a[d-b+1]+a[d-1]+a[d+1]+a[d+b-1]+a[d+b]+a[d+b+1];return c}
    6 changes: 4 additions & 2 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -25,9 +25,11 @@
    <div id="stage"></div>

    <a href="https://gist.github.com/1134658">Source</a>
    <script src="annotated.js" type="text/javascript" charset="utf-8"></script>


    <script>
    var life = function(a,b,c,d,e){for(d=c=[];d++<b*b;)e=a[d-b-1]+a[d-b]+a[d-b+1]+a[d-1]+a[d+1]+a[d+b-1]+a[d+b]+a[d+b+1],c[d]=e==3||a[d]&&e==2;return c},
    array = [],
    var array = [],
    elems = {},
    elem,
    stage = document.getElementById("stage"),
  13. @aemkei aemkei revised this gist Aug 14, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion annotated.js
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ function(
    neighbours =
    // count neighbours
    input[i-size-1] + input[i-size] + input[i-size+1] +
    input[i-1 ] + input[i+1 ] +
    input[i -1] + input[i +1] +
    input[i+size-1] + input[i+size] + input[i+size+1];

    output[i] =
  14. @aemkei aemkei revised this gist Aug 14, 2011. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -23,6 +23,8 @@
    </head>
    <body>
    <div id="stage"></div>

    <a href="https://gist.github.com/1134658">Source</a>
    <script>
    var life = function(a,b,c,d,e){for(d=c=[];d++<b*b;)e=a[d-b-1]+a[d-b]+a[d-b+1]+a[d-1]+a[d+1]+a[d+b-1]+a[d+b]+a[d+b+1],c[d]=e==3||a[d]&&e==2;return c},
    array = [],
  15. @aemkei aemkei revised this gist Aug 14, 2011. 2 changed files with 8 additions and 12 deletions.
    6 changes: 1 addition & 5 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -24,8 +24,4 @@ Created by Martin Kleppe ([@aemkei](http://twitter.com/aemkei)) at [Ubilabs](htt
    For more information
    --------------------

    See the [140byt.es](http://140byt.es) site for a showcase of entries (built itself using 140-byte entries!), and follow [@140bytes](http://twitter.com/140bytes) on Twitter.

    To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to [the wiki](https://github.com/jed/140bytes/wiki/Byte-saving-techniques).

    140byt.es is brought to you by [Jed Schmidt](http://jed.is), with help from Alex Kloss. It was inspired by work from [Thomas Fuchs](http://mir.aculo.us) and [Dustin Diaz](http://www.dustindiaz.com/).
    See the [140byt.es](http://140byt.es) site for a showcase of entries (built itself using 140-byte entries!), and follow [@140bytes](http://twitter.com/140bytes) on Twitter.
    14 changes: 7 additions & 7 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,13 @@
    {
    "name": "theNameOfYourLibWhichMustBeAValidCamelCasedJavaScriptIdentifier",
    "name": "gameOfLife",

    "description": "This should be a short description of your entry.",
    "description": "Implementation of Conway's Game of Live.",

    "keywords": [
    "five",
    "descriptive",
    "keywords",
    "or",
    "fewer"
    "conway",
    "game",
    "life",
    "cellular",
    "automaton"
    ]
    }
  16. @aemkei aemkei revised this gist Aug 14, 2011. 4 changed files with 66 additions and 93 deletions.
    31 changes: 15 additions & 16 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,25 @@
    140byt.es
    =========
    Game of Life - 140byt.es
    ========================

    A tweet-sized, fork-to-play, community-curated collection of JavaScript.
    An implementation of Conway's [Game of Life](http://en.wikipedia.org/wiki/Conway's_Game_of_Life) in less than 140 bytes of JavaScript.

    How to play
    -----------
    See the example: [ubilabs.net/projects/game-of-live](http://www.ubilabs.net/projects/game-of-live)

    1. Click the ![Fork](https://d3nwyuy0nl342s.cloudfront.net/images/gist/buttons/fork_button.png) button above to fork this gist.
    2. Modify all the files to according to the rules below.
    3. Save your entry and tweet it up!
    Usage
    -----

    Keep in mind that thanks to the awesome sensibilities of the GitHub team, gists are just repos. So feel free to clone yours and work locally for a more comfortable environment, and to allow commit messages.
    life (
    input, // input array
    size // size (width and height) of stage
    )

    // returns the modificated input string

    Rules
    -----
    All entries must exist in an `index.js` file, whose contents are

    1. an assignable, valid Javascript expression that
    2. contains no more than 140 bytes, and
    3. does not leak to the global scope.
    Author
    ------

    All entries must also be licensed under the [WTFPL](http://sam.zoy.org/wtfpl/) or equally permissive license.
    Created by Martin Kleppe ([@aemkei](http://twitter.com/aemkei)) at [Ubilabs](http://ubilabs.net/).

    For more information
    --------------------
    30 changes: 17 additions & 13 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,22 @@
    function life(input, size, output, i, sum){
    i = output = [];

    for (;i++ < size*size;) {
    function(
    input, // input array
    size, // size (width and height) of stage
    output, i, neighbours // placeholders
    ){
    // cycle through cells
    for (i = output = []; ++i < size*size;) {

    sum = input[i-size-1] +
    input[i-size] +
    input[i-size+1] +
    input[i-1] +
    input[i+1] +
    input[i+size-1] +
    input[i+size] +
    input[i+size+1];
    neighbours =
    // count neighbours
    input[i-size-1] + input[i-size] + input[i-size+1] +
    input[i-1 ] + input[i+1 ] +
    input[i+size-1] + input[i+size] + input[i+size+1];

    output[i] = sum == 3 || (input[i] && sum == 2)
    output[i] =
    // live if it has 3 neighbours
    neighbours == 3 ||
    // stay alive if it has 2 neighbours
    (input[i] && neighbours == 2);
    }

    return output;
    2 changes: 1 addition & 1 deletion index.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    function (a,b,c,d,e){d=c=[];for(;d++<b*b;)e=a[d-b-1]+a[d-b]+a[d-b+1]+a[d-1]+a[d+1]+a[d+b-1]+a[d+b]+a[d+b+1],c[d]=e==3||a[d]&&e==2;return c}
    function (a,b,c,d,e){for(d=c=[];d++<b*b;)e=a[d-b-1]+a[d-b]+a[d-b+1]+a[d-1]+a[d+1]+a[d+b-1]+a[d+b]+a[d+b+1],c[d]=e==3||a[d]&&e==2;return c}
    96 changes: 33 additions & 63 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,8 @@
    <!DOCTYPE html>
    <head>
    <title>Foo</title>
    <title>Game of Life</title>

    <style type="text/css" media="screen">


    #stage {
    line-height:12px;
    }
    @@ -15,76 +13,48 @@
    width: 10px;
    height: 10px;
    margin: 1px 1px 0 0;
    background-color: #000;
    }
    #stage div.dead {
    background-color: #EEE;
    }
    #stage div.alive {
    background-color: #000;
    }
    </style>

    </head>
    <body>

    <div id="stage"></div>
    <script>
    var life = function(a,b,c,d,e){for(d=c=[];d++<b*b;)e=a[d-b-1]+a[d-b]+a[d-b+1]+a[d-1]+a[d+1]+a[d+b-1]+a[d+b]+a[d+b+1],c[d]=e==3||a[d]&&e==2;return c},
    array = [],
    elems = {},
    elem,
    stage = document.getElementById("stage"),
    size = 50,
    x, y;

    <script src="annotated.js" type="text/javascript" charset="utf-8"></script>

    <script>


    (function(){

    var array = [],
    elems = {},
    elem,
    stage = document.getElementById("stage");
    size = 40;

    function randomize(){
    for (var x=0; x<size; x++){
    for (var y=0; y<size; y++){
    array.push(Math.random() < .5);
    }
    }
    }

    function render(array){
    var index = 0, color;

    for (var x=0; x<size; x++){
    for (var y=0; y<size; y++){
    elems[x + "," + y].className = array[index++] == 1 ? "alive" : "dead";
    }
    }
    }

    for (var x=0; x<size; x++){
    for (var y=0; y<size; y++){
    elem = document.createElement("div");
    stage.appendChild(elem);
    elem.title = x + "," + y;
    elems[x + "," + y] = elem;

    array.push(Math.random() < .5 ? 1 : 0);
    }

    elem = document.createElement("br");
    // create DOM elements
    for (x = 0; x < size; x++){
    for (y = 0; y < size; y++){
    elem = document.createElement("div");
    stage.appendChild(elem);

    }

    randomize();

    elems[x + "," + y] = elem;
    array.push(Math.random() < 0.5);
    }
    stage.appendChild(document.createElement("br"));
    }

    // render stage
    function play(){
    var index = 0, color;

    function play(){
    array = life(array, size);
    render(array);
    setTimeout(play, 20);
    array = life(array, size);
    for (x = 0; x < size; x++){
    for (y = 0; y < size; y++){
    elems[x + "," + y].className = array[index++] ? "alive" : "";
    }
    }

    play();


    })();
    setTimeout(play, 10);
    }
    play();
    </script>
    </body>
  17. @aemkei aemkei revised this gist Aug 14, 2011. 3 changed files with 106 additions and 19 deletions.
    27 changes: 18 additions & 9 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,19 @@
    function(){
    // make sure
    // to annotate
    // your code
    // so everyone
    // can learn
    // from it!
    // see jed's entries
    // for examples.
    function life(input, size, output, i, sum){
    i = output = [];

    for (;i++ < size*size;) {

    sum = input[i-size-1] +
    input[i-size] +
    input[i-size+1] +
    input[i-1] +
    input[i+1] +
    input[i+size-1] +
    input[i+size] +
    input[i+size+1];

    output[i] = sum == 3 || (input[i] && sum == 2)
    }

    return output;
    }
    2 changes: 1 addition & 1 deletion index.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    function(){/* Your entry, a useful, unique, and valid JavaScript expression that packs as much functionality into 140 bytes as possible. */}
    function (a,b,c,d,e){d=c=[];for(;d++<b*b;)e=a[d-b-1]+a[d-b]+a[d-b+1]+a[d-1]+a[d+1]+a[d+b-1]+a[d+b]+a[d+b+1],c[d]=e==3||a[d]&&e==2;return c}
    96 changes: 87 additions & 9 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,90 @@
    <!DOCTYPE html>
    <title>Foo</title>
    <div>Expected value: <b>undefined</b></div>
    <div>Actual value: <b id="ret"></b></div>
    <script>
    // write a small example that shows off the API for your example
    // and tests it in one fell swoop.
    <head>
    <title>Foo</title>

    <style type="text/css" media="screen">


    #stage {
    line-height:12px;
    }

    #stage div{
    display: block;
    float: left;
    width: 10px;
    height: 10px;
    margin: 1px 1px 0 0;
    background-color: #000;
    }
    #stage div.dead {
    background-color: #EEE;
    }
    </style>

    </head>
    <body>

    <div id="stage"></div>

    <script src="annotated.js" type="text/javascript" charset="utf-8"></script>

    <script>

    var myFunction = function(){ /* the code here should be identical to the entry. */ }

    document.getElementById( "ret" ).innerHTML = myFunction()
    </script>
    (function(){

    var array = [],
    elems = {},
    elem,
    stage = document.getElementById("stage");
    size = 40;

    function randomize(){
    for (var x=0; x<size; x++){
    for (var y=0; y<size; y++){
    array.push(Math.random() < .5);
    }
    }
    }

    function render(array){
    var index = 0, color;

    for (var x=0; x<size; x++){
    for (var y=0; y<size; y++){
    elems[x + "," + y].className = array[index++] == 1 ? "alive" : "dead";
    }
    }
    }

    for (var x=0; x<size; x++){
    for (var y=0; y<size; y++){
    elem = document.createElement("div");
    stage.appendChild(elem);
    elem.title = x + "," + y;
    elems[x + "," + y] = elem;

    array.push(Math.random() < .5 ? 1 : 0);
    }

    elem = document.createElement("br");
    stage.appendChild(elem);

    }

    randomize();


    function play(){
    array = life(array, size);
    render(array);
    setTimeout(play, 20);
    }

    play();


    })();
    </script>
    </body>
  18. @140bytes 140bytes revised this gist Jul 28, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ All entries must also be licensed under the [WTFPL](http://sam.zoy.org/wtfpl/) o
    For more information
    --------------------

    See the [140byt.es](http://140byt.es) for a showcase of entries built itself using 140-byte entries, and follow [@140bytes](http://twitter.com/140bytes) on Twitter.
    See the [140byt.es](http://140byt.es) site for a showcase of entries (built itself using 140-byte entries!), and follow [@140bytes](http://twitter.com/140bytes) on Twitter.

    To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to [the wiki](https://github.com/jed/140bytes/wiki/Byte-saving-techniques).

  19. @140bytes 140bytes revised this gist Jul 28, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -25,8 +25,8 @@ All entries must also be licensed under the [WTFPL](http://sam.zoy.org/wtfpl/) o
    For more information
    --------------------

    The [140byt.es](http://140byt.es) site hasn't launched yet, but for now follow [@140bytes](http://twitter.com/140bytes) on Twitter.
    See the [140byt.es](http://140byt.es) for a showcase of entries built itself using 140-byte entries, and follow [@140bytes](http://twitter.com/140bytes) on Twitter.

    To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to [the wiki](https://github.com/jed/140bytes/wiki/Byte-saving-techniques).

    140byt.es is brought to you by [Jed Schmidt](http://jed.is). It was inspired by work from [Thomas Fuchs](http://mir.aculo.us) and [Dustin Diaz](http://www.dustindiaz.com/).
    140byt.es is brought to you by [Jed Schmidt](http://jed.is), with help from Alex Kloss. It was inspired by work from [Thomas Fuchs](http://mir.aculo.us) and [Dustin Diaz](http://www.dustindiaz.com/).
  20. @140bytes 140bytes revised this gist Jun 1, 2011. 1 changed file with 5 additions and 7 deletions.
    12 changes: 5 additions & 7 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,12 @@
    <!DOCTYPE html>
    <body>
    <div>Expected value: <b>undefined</b></div>
    <div>Actual value: <b id="ret"></b></div>
    </body>
    <!DOCTYPE html>
    <title>Foo</title>
    <div>Expected value: <b>undefined</b></div>
    <div>Actual value: <b id="ret"></b></div>
    <script>
    // write a small example that shows off the API for your example
    // and tests it in one fell swoop.

    var myFunction = function(){ /* the code here should be identical to the entry. */ }
    var ret = myFunction()

    document.getElementById( "ret" ).innerHTML = ret
    document.getElementById( "ret" ).innerHTML = myFunction()
    </script>
  21. @140bytes 140bytes revised this gist Jun 1, 2011. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <!DOCTYPE html>
    <body>
    <div>Expected value: <b>undefined</b></div>
    <div>Actual value: <b id="ret"></b></div>
  22. @140bytes 140bytes revised this gist May 31, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion test.html
    Original file line number Diff line number Diff line change
    @@ -9,5 +9,5 @@
    var myFunction = function(){ /* the code here should be identical to the entry. */ }
    var ret = myFunction()

    document.getElementById( "ret" ) = ret
    document.getElementById( "ret" ).innerHTML = ret
    </script>
  23. @140bytes 140bytes revised this gist May 31, 2011. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions test.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    <body>
    <div>Expected value: <b>undefined</b></div>
    <div>Actual value: <b id="ret"></b></div>
    </body>
    <script>
    // write a small example that shows off the API for your example
    // and tests it in one fell swoop.

    var myFunction = function(){ /* the code here should be identical to the entry. */ }
    var ret = myFunction()

    document.getElementById( "ret" ) = ret
    </script>
  24. @140bytes 140bytes revised this gist May 31, 2011. 3 changed files with 17 additions and 19 deletions.
    17 changes: 9 additions & 8 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,10 @@
    function(){
    /* Rules:
    (1) anonymous function or IIFE // make sure
    (2) may execute immediately // to annotate
    (3) <=140 bytes // your code
    (4) no globals // so everyone
    (5) permissive license // can learn
    (6) have a good time! // from it!
    */}
    // make sure
    // to annotate
    // your code
    // so everyone
    // can learn
    // from it!
    // see jed's entries
    // for examples.
    }
    2 changes: 1 addition & 1 deletion index.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    function(){/******************************************************************************************************************************/}
    function(){/* Your entry, a useful, unique, and valid JavaScript expression that packs as much functionality into 140 bytes as possible. */}
    17 changes: 7 additions & 10 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,13 @@
    {
    // [REQUIRED] A name for your library.
    // This must match /^[a-z_]\w*$/i
    "name": "140bytes",
    "name": "theNameOfYourLibWhichMustBeAValidCamelCasedJavaScriptIdentifier",

    // [OPTIONAL] A description of your library, phrased as a verb predicate.
    // The gist description is used by default.
    "description": "Explain the 140byt.es rules.",
    "description": "This should be a short description of your entry.",

    // [OPTIONAL] Up to 5 keywords used for indexing.
    "keywords": [
    "140bytes",
    "master",
    "rules"
    "five",
    "descriptive",
    "keywords",
    "or",
    "fewer"
    ]
    }
  25. @140bytes 140bytes revised this gist May 26, 2011. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    function(){
    /* Rules:
    (1) anonymous function // make sure
    (2) may execute immediately // to annotate
    (3) <=140 bytes // your code
    (4) no globals // so everyone
    (5) permissive license // can learn
    (6) have a good time! // from it!
    (1) anonymous function or IIFE // make sure
    (2) may execute immediately // to annotate
    (3) <=140 bytes // your code
    (4) no globals // so everyone
    (5) permissive license // can learn
    (6) have a good time! // from it!
    */}
  26. @140bytes 140bytes revised this gist May 25, 2011. 3 changed files with 8 additions and 8 deletions.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ Rules
    -----
    All entries must exist in an `index.js` file, whose contents are

    1. an assignable, valid Javascript expression, that
    1. an assignable, valid Javascript expression that
    2. contains no more than 140 bytes, and
    3. does not leak to the global scope.

    12 changes: 6 additions & 6 deletions annotated.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    function(){
    /* Rules:
    (1) anonymous function // make sure
    (2) may be self-executing // to annotate
    (3) <=140 bytes // your code
    (4) no globals // so everyone
    (5) MIT license // can learn
    (6) have a good time! // from it!
    (1) anonymous function // make sure
    (2) may execute immediately // to annotate
    (3) <=140 bytes // your code
    (4) no globals // so everyone
    (5) permissive license // can learn
    (6) have a good time! // from it!
    */}
    2 changes: 1 addition & 1 deletion index.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    function(){/*Rules: (1) anonymous function (2) may be self-executing (3) <=140 bytes (4) no globals (5) MIT license (6) have a good time!*/}
    function(){/******************************************************************************************************************************/}
  27. @140bytes 140bytes revised this gist May 23, 2011. 2 changed files with 14 additions and 21 deletions.
    33 changes: 13 additions & 20 deletions LICENSE.txt
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,13 @@
    Copyright (c) 2011 YOUR_NAME_HERE, YOUR_URL_HERE

    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    "Software"), to deal in the Software without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:

    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
    Version 2, December 2004

    Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>

    Everyone is permitted to copy and distribute verbatim or modified
    copies of this license document, and changing it is allowed as long
    as the name is changed.

    DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

    0. You just DO WHAT THE FUCK YOU WANT TO.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ All entries must exist in an `index.js` file, whose contents are
    2. contains no more than 140 bytes, and
    3. does not leak to the global scope.

    All entries must also be licensed under a license as or more permitting than the MIT license.
    All entries must also be licensed under the [WTFPL](http://sam.zoy.org/wtfpl/) or equally permissive license.

    For more information
    --------------------
  28. @140bytes 140bytes revised this gist May 23, 2011. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -16,12 +16,11 @@ Rules
    -----
    All entries must exist in an `index.js` file, whose contents are

    1. a valid Javascript function expression, that
    2. optionally self-executes,
    1. an assignable, valid Javascript expression, that
    2. contains no more than 140 bytes, and
    3. does not pollute global scope.
    3. does not leak to the global scope.

    All entries must also be licensed under the MIT license.
    All entries must also be licensed under a license as or more permitting than the MIT license.

    For more information
    --------------------
  29. @140bytes 140bytes revised this gist May 22, 2011. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,8 @@ How to play
    2. Modify all the files to according to the rules below.
    3. Save your entry and tweet it up!

    Keep in mind that thanks to the awesome sensibilities of the GitHub team, gists are just repos. So feel free to clone yours and work locally for a more comfortable environment, and to allow commit messages.

    Rules
    -----
    All entries must exist in an `index.js` file, whose contents are
  30. @140bytes 140bytes revised this gist May 21, 2011. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -26,4 +26,6 @@ For more information

    The [140byt.es](http://140byt.es) site hasn't launched yet, but for now follow [@140bytes](http://twitter.com/140bytes) on Twitter.

    To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to [the wiki](https://github.com/jed/140bytes/wiki/Byte-saving-techniques).

    140byt.es is brought to you by [Jed Schmidt](http://jed.is). It was inspired by work from [Thomas Fuchs](http://mir.aculo.us) and [Dustin Diaz](http://www.dustindiaz.com/).