Skip to content

Instantly share code, notes, and snippets.

@misterhat
Last active November 21, 2016 19:22
Show Gist options
  • Select an option

  • Save misterhat/518814835148aa20a3e3c0aa6acd2d39 to your computer and use it in GitHub Desktop.

Select an option

Save misterhat/518814835148aa20a3e3c0aa6acd2d39 to your computer and use it in GitHub Desktop.
var GridPaint = require('gridpaint');
var painter = new GridPaint({ width: 26, height: 15, cellWidth: 16 }),
d, actions;
document.body.appendChild(painter.dom);
d = document.createElement('div');
d.style.marginBottom = '6px';
painter.palette.forEach(function (colour, i) {
var b = document.createElement('button');
b.style.backgroundColor = colour;
b.style.border = '1px solid #000';
b.style.marginRight = '4px';
b.style.color = 'white';
b.innerText = '\xa0';
b.title = 'switch to ' + colour;
b.onclick = function () {
painter.colour = i;
};
d.appendChild(b);
});
document.body.appendChild(d);
d = document.createElement('div');
actions = [ 'pencil', 'bucket', 'undo', 'redo', 'clear', 'saveAs' ];
actions.forEach(function (action, i) {
var b = document.createElement('button');
b.innerText = action;
b.onclick = function () {
if (i < 2) {
painter.tool = action;
} else {
painter[action]();
}
};
d.appendChild(b);
});
document.body.appendChild(d);
painter.init()
{
"name": "gridpaint-example",
"version": "0.0.0",
"dependencies": {
"gridpaint": "^0.0.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment