Skip to content

Instantly share code, notes, and snippets.

@samkingco
Created October 30, 2021 00:02
Show Gist options
  • Select an option

  • Save samkingco/1dbae7db9894b3af05881b81c351fcae to your computer and use it in GitHub Desktop.

Select an option

Save samkingco/1dbae7db9894b3af05881b81c351fcae to your computer and use it in GitHub Desktop.
Create designs for the T83 NFT project
function gridToPairOfUint160(grid) {
let gridR = grid.map((_, index) => [grid].map((row) => row[index]).reverse());
let grid2R = gridR[0].map((_, index) =>
gridR.map((row) => row[index]).reverse()
)[0];
let leftPart = 0n;
let rightPart = 0n;
for (let i = 0; i < 14; i++) {
for (let j = 0; j < 22; j++) {
const power = BigInt(13 - i) + 14n * BigInt(j % 11);
const diff = grid2R[i][j] ? 2n ** power : 0n;
if (j < 11) {
leftPart += diff;
} else {
rightPart += diff;
}
}
}
const leftCode = leftPart.toString();
const rightCode = rightPart.toString();
return `${leftCode}, ${rightCode}`;
}
const design = [
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
];
const grid = design.map((row) => row.map((i) => i === 1));
console.log(gridToPairOfUint160(grid));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment