Comparing version 0.0.4 to 0.0.5
@@ -41,9 +41,9 @@ const { Art } = require("./_base.js"); | ||
computeIdealLayout(w, h, grids) { | ||
const idealNegativeSpace = (w * h) / 4; | ||
let bestLayout = { negativeSpace: 0 }; | ||
const idealNegativeSpace = (w * h) / 2; | ||
let bestLayout = { negativeSpace: Infinity }; | ||
for (let rows = 1; rows < grids.length; rows++) { | ||
for (let padding = 16; padding < 100; padding += 3) { | ||
for (let puzzleSize = 64; puzzleSize < 200; puzzleSize += 16) { | ||
let columns = Math.ceil(grids.length / rows); | ||
for (let columns = 1; columns < grids.length; columns++) { | ||
for (let puzzleSize = 8; puzzleSize < 200; puzzleSize += 4) { | ||
for (let padding = puzzleSize / 4; padding < puzzleSize; padding += 1) { | ||
let rows = Math.ceil(grids.length / columns); | ||
let layoutWidth = columns * puzzleSize + (columns + 1) * padding; | ||
@@ -60,6 +60,4 @@ let layoutHeight = rows * puzzleSize + (rows + 1) * padding; | ||
w * h - | ||
// Subtract the area the layout takes up | ||
layoutWidth * layoutHeight + | ||
// We took out too much! Add back the total area of the puzzles | ||
puzzleSize * rows * columns; | ||
// Subtract the area of the puzzles | ||
puzzleSize * puzzleSize * columns * rows; | ||
@@ -72,4 +70,4 @@ if ( | ||
negativeSpace, | ||
columns, | ||
rows, | ||
columns, | ||
layoutWidth, | ||
@@ -122,8 +120,10 @@ layoutHeight, | ||
// the direction of the block we'll be moving | ||
const moves = Array.from(movesBuffer).flatMap((byte) => [ | ||
byte >> 6, | ||
(byte >> 4) % 4, | ||
(byte >> 2) % 4, | ||
byte % 4, | ||
]); | ||
const moves = [].concat( | ||
...Array.from(movesBuffer).map((byte) => [ | ||
byte >> 6, | ||
(byte >> 4) % 4, | ||
(byte >> 2) % 4, | ||
byte % 4, | ||
]) | ||
); | ||
@@ -158,3 +158,3 @@ moves.forEach((move) => { | ||
const { rows, columns, layoutWidth, layoutHeight, padding, puzzleSize } = | ||
this.computeIdealLayout(w, h, grids); | ||
this.computeIdealLayout(w * 0.9, h * 0.9, grids); | ||
@@ -168,7 +168,7 @@ grids.forEach((grid, idx) => { | ||
column * puzzleSize + | ||
padding * (column + 1); | ||
(column + 1) * padding; | ||
const y = | ||
Math.floor(h / 2 - layoutHeight / 2) + | ||
row * puzzleSize + | ||
padding * (row + 1); | ||
(row + 1) * padding; | ||
@@ -175,0 +175,0 @@ this.drawPuzzle(ctx, x, y, puzzleSize, grid); |
{ | ||
"name": "hashart", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "dev": "next dev", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1517062