【问题标题】:Why is Processing.js giving me an error about a function that isn't in my code?为什么 Processing.js 给我一个关于我的代码中没有的函数的错误?
【发布时间】:2018-09-10 23:18:06
【问题描述】:

所以我使用 processing.js 来制作一些看起来很抽象的排版(例如 this),并且我找到了某人的代码,我想将其用作我自己代码的基础。我尝试将其复制并粘贴到打开的处理中,用于处理的在线编辑器,当我尝试运行它时它给了我这个错误:drawing.$ensureContext(...).getImageData is not a function

here是代码:

PImage hm;
int xstep = 1;
int max_height = 60;
 
void setup() {
  size(600, 400, P3D);
  background(0);
  fill(255);
  textSize(128);
  textAlign(CENTER);
  text("LIGMA", width/2, height/2);
  filter(BLUR, 8);
  hm = get();
}
 
void draw() {
  background(0);
  strokeWeight(2);
  stroke(255);
  float b, z, px, pz;
  translate(width/2, height/2,-20);
  rotateY(map(mouseX,0,width,-PI,PI));
  rotateX(map(mouseY,0,height,-PI,PI));
 
  translate(-width/2, -height/2);
  for (int y = 5; y < height; y+=10) {
    px = -1;
    pz = 0;
    for (int x = 0; x < width; x+=xstep) {
      b = brightnes(hm.get(x,y));
      z = map(b, 0, 200, 0, max_height);
      //stroke(color(b));
      line(px, y, pz, x, y, z);
      px = x;
      pz = z;
    }
  }
}

在我的代码中找不到这个drawing.$ensureContext(...).getImageData。谁能解释为什么会发生这种情况以及如何解决?

【问题讨论】:

  • 异常通常会告诉你文件和行
  • 如果您打开开发者工具,您可以在控制台中看到完整的异常。它看起来像是源自处理库本身的错误。
  • @Jacob 有开发者工具在处理吗?
  • Processing.js 已经很老了,不再推荐用于新代码。另请注意,您的代码无法编译,因为您拼错了brightness
  • @mckuok 它没有

标签: javascript processing typography processing.js


【解决方案1】:

问题可能来自此代码行和P3D 上下文:

filter(BLUR, 8);

由于filter() 等待图像,PImage 对象正在处理中,因此无法找到。 删除它,错误就会出来。

查看this 文档,上面写着:

描述:过滤由以下模式之一定义的图像:

filter() 使用aImg.loadPixels(),其中aImg 是图像,这是ProcessingJS 源代码中的函数loadPixels

p.loadPixels = function() {
  p.imageData = drawing.$ensureContext().getImageData(0, 0, p.width, p.height);
};

这不是提醒你什么吗? :)

【讨论】:

    猜你喜欢
    • 2016-09-18
    • 2023-01-18
    • 2021-06-09
    • 1970-01-01
    • 1970-01-01
    • 2022-08-09
    • 1970-01-01
    • 1970-01-01
    • 2014-01-09
    相关资源
    最近更新 更多