0

我正在修改在 observablehq.com 上找到的算法。我的目标是提取从工作人员发送消息的数据并将其保存到文本/csv 文件中。我正在尝试保存数组“点”和“权重”,但我不知道从哪里开始。

sobelDotsWorker = {
  if (renderSobel){
    const context = sobelDotsContext;
    const worker = new Worker(sobeldotsScript);
    mutable sobelDotsRenders = 0;
    function messaged({data: {points, weights}}) {
      context.fillStyle = "#000";
      context.fillRect(0, 0, width, height);
      context.fillStyle = "#FFF";
      context.beginPath();
      for (let i = 0, n = points.length; i < n; i += 2) {
        const w = Math.max(0.5, Math.sqrt(weights[i>>1])*0.5);
        if (w > 0.25) {
          const x = points[i];
          const y = points[i + 1];
          context.moveTo(x + w, y + w);
          context.arc(x, y, w, 0, 2 * Math.PI);
        }
      }
      context.fill();
      mutable sobelDotsRenders += 1;
    }

    invalidation.then(() => worker.terminate());
    worker.addEventListener("message", messaged);
    worker.postMessage({data: imageGray.dark, sobelData: imageSobel.sobel, width, height, n, iterations});
    yield worker;
  }
}

这是原始代码。

4

0 回答 0