Last active
August 29, 2015 14:09
Revisions
-
wilson428 revised this gist
Nov 13, 2014 . 3 changed files with 10 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,10 @@ var Raphael = require("raphael-browserify"), 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("canvas", 500, 200); var marbles = paper.set(); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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", "domify": "1.3.1" } } -
wilson428 created this gist
Nov 13, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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" } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ made with [requirebin](http://requirebin.com)