Skip to content

Instantly share code, notes, and snippets.

@francisbesset
Forked from Dan-Q/jigidi-helper.js
Last active March 19, 2023 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francisbesset/2c4f19d5516aa46cfc94a74e46e643be to your computer and use it in GitHub Desktop.
Save francisbesset/2c4f19d5516aa46cfc94a74e46e643be to your computer and use it in GitHub Desktop.
Experimental under-development code to streamline Jigidi solving.

Jigidi Helper (Experimental)

Replaces the image of a jigsaw puzzle with a predictable, (theoretically) easier-to-solve design.

Partially-solved jigsaw, post-tampering.

How to use

  1. Begin a Jigidi puzzle.
  2. Run the code in your browser debug console.
  3. Restart the puzzle by pressing the Restart button in the Jigidi sidebar.
  4. The puzzle will be replaced with a predictable patterned one.

How does this help?

The predictable pattern has a number of features that make it easier to solve that most other jigsaws:

  • Each piece has two numbers printed on it: the first is the row in which it belongs, the second is the column, making it possible to identify the exact location that a given piece belongs in.
  • Each column is a different colour, streamlining presorting.
  • Rows within a column alternate between lighter and darker variants ("striping").
  • Stripes of alternating thickness and a cycle of colours form long horizonal and vertical bands across the image, streamlining identification.
  • No information is sent back to the server to indicate that the puzzle has been tampered with.
window.jColors = ['#FF0000','#FFFF00','#FFA500','#00FF00','#FF69B4','#0000FF','#FF00FF','#00FFFF'];
window.lColors = ['white', 'black', 'purple', 'darkgray', '#009'];
window.lWidths = [5, 10, 20];
window.jCols = parseInt(document.getElementById('info-creator').innerText.match(/(\d+)×/)[1]);
window.jC = 0;
CanvasRenderingContext2D.prototype.pickTextColorBasedOnBgColorAdvanced = function(bgColor, lightColor, darkColor) {
var color = (bgColor.charAt(0) === '#') ? bgColor.substring(1, 7) : bgColor;
var r = parseInt(color.substring(0, 2), 16);
var g = parseInt(color.substring(2, 4), 16);
var b = parseInt(color.substring(4, 6), 16);
var uicolors = [r / 255, g / 255, b / 255];
var c = uicolors.map((col) => {
if (col <= 0.03928) {
return col / 12.92;
}
return Math.pow((col + 0.055) / 1.055, 2.4);
});
var L = (0.2126 * c[0]) + (0.7152 * c[1]) + (0.0722 * c[2]);
return (L > 0.179) ? darkColor : lightColor;
};
CanvasRenderingContext2D.prototype.putImageData = function(imageData, dx, dy){
const col = window.jC % window.jCols;
const row = Math.floor(window.jC / window.jCols);
const bgColor = window.jColors[col % window.jColors.length];
this.fillStyle = bgColor;
this.fillRect(-1000,-1000,2000,2000);
if(0 == (row % 2)){ this.fillStyle = '#ffffff33'; this.fillRect(-1000,-1000,2000,2000); }
this.fillStyle = window.lColors[row % window.lColors.length];
this.fillRect(-1000, -35, 2000, window.lWidths[row % window.lWidths.length]);
this.fillStyle = window.lColors[col % window.lColors.length];
this.fillRect(-35, -1000, window.lWidths[col % window.lWidths.length], 2000);
this.font = 'bold 14px sans-serif';
this.fillStyle = this.pickTextColorBasedOnBgColorAdvanced(bgColor, '#FFFFFF', '#000000');
this.fillText(`${row+1},${col+1}`, -5, 0);
window.jC++;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment