nonogram.Editor

new nonogram.Editor(4, 8, 'edit1', {
  theme: {
    threshold: 0.2,
    isMeshed: true,
    boldMeshGap: 2,
  },
});
new nonogram.Editor(2, 4, 'edit2', {
  grid: [[1, 0, 1, 0], [0, 1, 0, 1]],
});

nonogram.Game

new nonogram.Game([[1,1], [1,1]], [[1], [1], [1], [1]], 'play1', {
  theme: {
    filledColor: '#0c6',
    correctColor: '#0c6',
  }
});
new nonogram.Game([[1,1], [1,1]], [[2], [], [2], []], 'play2');

nonogram.Solver

new nonogram.Solver([[1,1], [1,1]], [[2], [], [2], []], 'solve1', {
  delay: 200,
}).solve();
var row = [
  [7, 2, 2, 7],
  [1, 1, 1, 2, 1, 1],
  [1, 3, 1, 3, 1, 1, 3, 1],
  [1, 3, 1, 2, 1, 1, 3, 1],
  [1, 3, 1, 2, 1, 3, 1],
  [1, 1, 2, 2, 1, 1],
  [7, 1, 1, 1, 7],
  [2],
  [2, 3, 2, 1, 4],
  [1, 1, 3, 3, 2, 1],
  [3, 1, 3, 2, 2],
  [1, 1, 1, 3, 1, 1],
  [1, 5, 1, 1, 1, 1],
  [1, 1, 1, 1, 3, 1],
  [7, 1, 1],
  [1, 1, 1, 1, 1, 1, 1, 1],
  [1, 3, 1, 1, 1, 2, 2],
  [1, 3, 1, 2, 1, 2, 1, 1],
  [1, 3, 1, 1, 1, 2],
  [1, 1, 2, 1, 1],
  [7, 1, 3, 1]
];
var column = [
  [7, 1, 2, 7],
  [1, 1, 1, 1, 1, 1],
  [1, 3, 1, 1, 1, 3, 1],
  [1, 3, 1, 1, 1, 1, 3, 1],
  [1, 3, 1, 1, 1, 1, 3, 1],
  [1, 1, 2, 1, 1],
  [7, 1, 1, 1, 7],
  [4],
  [4, 2, 2, 2, 2, 2],
  [1, 2, 1, 1, 1, 2, 3],
  [1, 2, 2, 2],
  [2, 3, 1, 1, 1, 1, 1],
  [3, 3, 2, 3, 1, 1],
  [1, 1, 3, 2],
  [7, 1, 1],
  [1, 1, 1, 1, 1, 1, 1],
  [1, 3, 1, 3, 2, 3],
  [1, 3, 1, 2, 2, 1, 1],
  [1, 3, 1, 1, 1, 1, 1],
  [1, 1, 5, 3],
  [7, 1, 1, 2, 1]
];
new
  nonogram.Solver(
    row,
    column,
    'solve2')
  .solve();

Advanced Usages

Create Your Own Nonogram

Here is an example showing how to use listeners to create nonogram.Game and nonogram.Solver instances automatically.

function f() {
  new nonogram.Editor(
    +document.getElementById('m').value,
    +document.getElementById('n').value,
    'adv-edit1',
    {
      threshold: +document.getElementById('threshold').value,
      onHintChange: function (row, column) {
        new nonogram.Game(row, column, 'adv-play1', { theme: { boldMeshGap: 0 } });
        new nonogram.Solver(row, column, 'adv-solve1').solve();
      },
    }
  );
}
document.getElementById('m').addEventListener('change', f);
document.getElementById('n').addEventListener('change', f);
document.getElementById('threshold').addEventListener('change', f);
f();

Interactive Nonogram Solver

This example shows how to solve the nonogram by given hints, which are separated by newlines and commas.

Put your rows in the first textarea, columns in the second textarea. One row (or column) a line, numbers separated by any non-numerical characters. To represent an empty row (or column), you can use an empty line, or a line including the number 0 as well. However, empty lines at two ends will be dropped, since they are really unnecessary.

If the process end with an error, please check your input carefully.

Delay: 0~500ms. Setting delay=0 disables step-by-step solution, with a much smaller time cost.

Parse JSON-like strings or anything.

function parseArray(str) {
  str = str.replace(/[^\d\n]+/g, ' ').trim();
  var hints = str.split('\n');
  hints.forEach(function (str, i, hints) {
    var t = str.match(/\d+/g) || [];
    t = t.map(parseFloat);
    hints[i] = t.filter(Math.sign);
  });
  return hints;
}
document.getElementById('btn-solve2').addEventListener('click', function () {
  var delay = +document.getElementById('delay').value;
  new nonogram.Solver(
    parseArray(document.getElementById('txt-row-hints2').value),
    parseArray(document.getElementById('txt-col-hints2').value),
    'adv-solve2',
    {
      theme: {
        isMeshed: true,
        isBoldMeshOnly: true,
        isMeshOnTop: true,
      },
      delay: delay,
      onSuccess: function (time) {
        document.getElementById('timecost').innerHTML =
        'Solved in ' + time + 'ms.'
      },
    }).solve();
});