Skip to content

Instantly share code, notes, and snippets.

@wilson428
Last active August 29, 2015 14:09

Revisions

  1. wilson428 revised this gist Nov 13, 2014. 3 changed files with 10 additions and 4 deletions.
    9 changes: 7 additions & 2 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,10 @@
    var Raphael = require("raphael-browserify"),
    shuffle = require('shuffle-array');
    shuffle = require('shuffle-array'),
    domify = require('domify');

    var body = "<div id='canvas'><div id='controls'><button>PLAY</button></div>";

    document.body.appendChild(domify(body))

    // bag of marbles will be represented as an array of strings: ["green", "blue", "blue", ... ]
    function makeMarbles(ratios) {
    @@ -17,7 +22,7 @@ var bag = makeMarbles({
    lightblue: 25
    });

    var paper = Raphael(0, 0, 500, 500);
    var paper = Raphael("canvas", 500, 200);

    var marbles = paper.set();

    2 changes: 1 addition & 1 deletion minified.js
    1 addition, 1 deletion not shown because the diff is too large. Please use a local Git client to view these changes.
    3 changes: 2 additions & 1 deletion package.json
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@
    "version": "1.0.0",
    "dependencies": {
    "raphael-browserify": "2.1.0",
    "shuffle-array": "0.0.2"
    "shuffle-array": "0.0.2",
    "domify": "1.3.1"
    }
    }
  2. wilson428 created this gist Nov 13, 2014.
    40 changes: 40 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    var Raphael = require("raphael-browserify"),
    shuffle = require('shuffle-array');

    // bag of marbles will be represented as an array of strings: ["green", "blue", "blue", ... ]
    function makeMarbles(ratios) {
    var bag = [];
    for (var color in ratios) if (ratios.hasOwnProperty(color)) {
    for (var c = 0; c < ratios[color]; c += 1) {
    bag.push(color);
    }
    }
    return shuffle(bag);
    }

    var bag = makeMarbles({
    orange: 75,
    lightblue: 25
    });

    var paper = Raphael(0, 0, 500, 500);

    var marbles = paper.set();

    function drawMarbles(bag) {
    marbles.remove();
    marbles.clear();

    var row = 0,
    columns = 20,
    spacing = 20;

    while (row * columns < bag.length) {
    for (var c = 1; c <= columns; c += 1) {
    marbles.push(paper.circle(spacing * c, spacing * (row + 1), spacing/2 - 2).attr("fill", bag[row * columns + c - 1]));
    }
    row += 1;
    }
    }

    drawMarbles(bag);
    4 changes: 4 additions & 0 deletions minified.js
    4 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
    8 changes: 8 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    {
    "name": "requirebin-sketch",
    "version": "1.0.0",
    "dependencies": {
    "raphael-browserify": "2.1.0",
    "shuffle-array": "0.0.2"
    }
    }
    2 changes: 2 additions & 0 deletions page-head.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    <style type='text/css'>html, body { margin: 0; padding: 0; border: 0; }
    body, html { height: 100%; width: 100%; }</style>
    1 change: 1 addition & 0 deletions requirebin.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    made with [requirebin](http://requirebin.com)