Commit d756e583 authored by Grant's avatar Grant
Browse files

v1

parents
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+4 −0
Original line number Diff line number Diff line
data
frames
node_modules
 No newline at end of file

package-lock.json

0 → 100644
+0 −0

File added.

Preview size limit exceeded, changes collapsed.

package.json

0 → 100644
+24 −0
Original line number Diff line number Diff line
{
  "name": "canvas-timelapse",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "tsx src/index.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": "",
  "devDependencies": {
    "@tsconfig/recommended": "^1.0.7",
    "@types/node": "^20.14.10",
    "tsx": "^4.16.2",
    "typescript": "^5.5.3"
  },
  "dependencies": {
    "canvas": "github:Automattic/node-canvas",
    "pureimage": "^0.4.13",
    "ts-node": "^10.9.2"
  }
}

src/fix_file.ts

0 → 100644
+12 −0
Original line number Diff line number Diff line
import fs from "fs";

const file = fs.readFileSync("./tofix.txt", "utf8");

const lines = file.split("\n").map((line) => {
  line = line.trim();
  let parts = line.split("|");
  parts.splice(2, 0, "pixel_place");
  return parts.join("\t");
});

fs.writeFileSync("./tofix.txt", lines.join("\n"));

src/index.ts

0 → 100644
+66 −0
Original line number Diff line number Diff line
import fs from "node:fs";
import { createCanvas } from "canvas";
import { WORKER_COUNT, getWorker, spawnWorker, spawnWorkers } from "./worker";

const CANVAS_SIZE = [1000, 500];
const OUTPUT_SIZE = [CANVAS_SIZE[0] * 2, CANVAS_SIZE[1] * 2];

const file = fs.readFileSync("./pixels.log", "utf8");
const lines = file.split("\n");

const pixels: {
  date: number;
  x: number;
  y: number;
  hex: "unset" | string;
  who: string;
}[] = [];

for (const line of lines) {
  // type: pixel_place | pixel_undo | mod_rollback
  const [timestamp, handle, type, x, y, hex] = line.split("\t");

  if (!type || !x || !y || !hex) {
    console.log("error line:", line);
  } else {
    pixels.push({
      date: new Date(timestamp).getTime(),
      x: parseInt(x),
      y: parseInt(y),
      hex,
      who: handle.toLowerCase(),
    });
  }
}

const start = pixels[0].date;
const end = pixels[pixels.length - 1].date;

// const start = 1720843200000; // 7/12 10:00pm mountain
// const end = start + 1000 * 60 * 60;
// const end = 1720929600000; // 7/13 10:00pm mountain
// const filterByAccounts = [];
const step_ms = 1000 * 60;
const framesPerStep = Math.floor((end - start) / step_ms);

spawnWorkers().then(() => {
  let index = 0;
  for (let time = start; time < end; time += (end - start) / WORKER_COUNT) {
    console.log(
      "Progress: " + (((time - start) / (end - start)) * 100).toFixed(2) + "%"
    );
    const pixelsInFrame = pixels.filter(
      // (pixel) => pixel.date >= time && pixel.date <= time + step_ms
      (pixel) => pixel.date <= time + (end - start) / WORKER_COUNT
    );

    getWorker().postMessage({
      frameStart: framesPerStep * index,
      start: time,
      end: time + (end - start) / WORKER_COUNT,
      step: step_ms,
      pixels: pixelsInFrame,
    });
    index++;
  }
});