我的草图在Processing中运行时不会显示任何内容。

huangapple go评论68阅读模式
英文:

My sketch won't show anything when running in processing

问题

以下是您提供的翻译内容:

我完全不了解processing,我想通过创建一个简单的草图来测试它,草图会绘制一个矩形,但是当我运行草图时,弹出一个空白窗口。我尝试过填充它,给它加上轮廓以及其他各种方法,但什么都没有发生。我认为问题不在于代码,而在于应用程序本身,我不确定如何解决。我正在使用Windows上的processing 3.5.4。

代码:

class Sketch {
  void setup() {
    size(100, 100);
  }
  
  void draw() {
    rect(50, 50, 25, 25);
  }
}

预期输出:屏幕上显示一个正方形。

输出:什么都没有显示出来。

英文:

I am completely new to processing, and I wanted to test it by creating a simple sketch that draws a rectangle, however, when i run the sketch, a window pops up with nothing on it. I tried filling it, putting an outline on it, and various other things, nothing happened. I don't think it's a problem with the code but a problem with the app itself, and i'm not sure how to fix it. I am using processing 3.5.4 on windows.

Code:

class Sketch {
  void setup() {
    size(100, 100);
  }
  
  void draw() {
    rect(50, 50, 25, 25);
  }
}

Expected Output: A square shows up on screen.

Output: Nothing shows up

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;iframe src=&quot;https://drive.google.com/file/d/1gAQsX0hpAyH_iSbUXkyO87a8NpXscLEL/preview&quot; width=&quot;640&quot; height=&quot;480&quot;&gt;&lt;/iframe&gt;

<!-- end snippet -->

答案1

得分: 1

以下是翻译好的内容:

明显的观点(如果我没有正确理解你的问题,请不要责怪我):

draw()setup() 已经是 Processing 的一部分。实际上,你将它们写到一个类中,它们不会自动执行,因为 Processing 会寻找它自己的方法。这就是为什么你会得到这个结果:

我的草图在Processing中运行时不会显示任何内容。

事实上,这与你运行一个空白的草图的结果完全相同。

要解决这个问题,只需将 draw()setup() 从类中移出,然后 Processing 就会找到并执行它们:

void setup() {
  size(100, 100);
}

void draw() {
  rect(50, 50, 25, 25);
}

我的草图在Processing中运行时不会显示任何内容。

玩得开心!

英文:

Chiming in with the obvious (don't hurt me if I didn't get your question right):

draw() and setup() are already of Processing. In fact, those you wrote into a class won't be automatically executed, as Processing will be looking for it's own methods. That's why you get this:

我的草图在Processing中运行时不会显示任何内容。

Which is, incidentally, exactly the same result as if you ran an empty sketch.

To fix this, just take draw() and setup() out of the class, and Processing will then find and run them:

void setup() {
  size(100, 100);
}

void draw() {
  rect(50, 50, 25, 25);
}

我的草图在Processing中运行时不会显示任何内容。

Have fun!

huangapple
  • 本文由 发表于 2020年9月13日 22:29:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/63871914.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定