|
@@ -134,17 +134,34 @@ mapData.grid.forEach((color, coords) => {
|
|
|
if (!imageData[column]) { imageData[column] = []; }
|
|
|
imageData[column][row] = color;
|
|
|
});
|
|
|
-// Flatten it into one array, and replace undefined's with 0's
|
|
|
-imageData = imageData.flat().map((color) => (color === undefined ? 0 : color));
|
|
|
+
|
|
|
+// Flatten it into one array, and replace undefined's with null's
|
|
|
+imageData = imageData.map(fillEmptySlotsWithZero)
|
|
|
+ .map((row) => { while (row.length < 43) { row.push(0); } return row; })
|
|
|
+ .flat();
|
|
|
// Join it into a data stream
|
|
|
imageData = imageData.join("");
|
|
|
// Create and render the image
|
|
|
|
|
|
+// Height was found from this post: https://old.reddit.com/r/adventofcode/comments/e93d3y/2019_day_11_part_2_animated_python_output/
|
|
|
+// Width was brute forced
|
|
|
const height = 6;
|
|
|
+const width = 43;
|
|
|
+
|
|
|
+// Render Robby's path as a Space Image
|
|
|
+const identifier = new SpaceImageFormat(width, height, imageData);
|
|
|
+identifier.Render();
|
|
|
+console.log();
|
|
|
|
|
|
-for (let width = 40; width < 50; width++) {
|
|
|
- console.log(`Dimensions: ${width}x${height}`);
|
|
|
- const identifier = new SpaceImageFormat(width, height, imageData);
|
|
|
- identifier.Render();
|
|
|
- console.log();
|
|
|
+/**
|
|
|
+ * Fill empty slots in an array with zeros
|
|
|
+ *
|
|
|
+ * @param {array} arr The array to fill
|
|
|
+ * @returns {array} The input array with no empty spots
|
|
|
+ */
|
|
|
+function fillEmptySlotsWithZero(arr) {
|
|
|
+ return Array.from(arr, (_, i) => {
|
|
|
+ if (!(i in arr)) { return 0; }
|
|
|
+ return arr[i];
|
|
|
+ });
|
|
|
}
|