我猜我正在尝试制作一种抽象的对象,引用该书处理创意编码示例

发布于 2025-01-31 06:18:26 字数 745 浏览 4 评论 0原文

这是代码,如果需要,我可以获取所有内容的屏幕截图,但是我只是遇到一个错误 - “您可能会混合活动和静态模式的语法错误”。

我对此非常陌生,所以任何帮助都会很棒。

float boxSize = 40;
float margin = boxSize*2;
float depth = 400;
color boxFill;
void setup(){
size(500,500,P3D);
}

void draw(){
translate(width/2, height/2, -depth/2);
rotateY(frameCount*PI/60);
rotateX(frameCount*PI/60);
}
for (float i=-depth/2+margin; i<=depth/2-margin; i+=boxSize){
pushMatrix();
for (float j=-height/2+margin; j<=height/2-margin; j+=boxSize){
pushMatrix();

for (float k=-width/2+margin; k<=width/2-margin; k+=boxSize){
  boxFill = color(abs(i), abs(j), abs(k), 50);
pushMatrix();
translate(k, j, i);
fill(boxFill);
box(boxSize, boxSize, boxSize);
popMatrix();
}
popMatrix();
}
popMatrix();
}
}

Here is the code, i can get screenshots of everything if need be, but Im just getting one error - "syntax error you might be mixing active and static modes."

Im fairly new to this so any help would be great.

float boxSize = 40;
float margin = boxSize*2;
float depth = 400;
color boxFill;
void setup(){
size(500,500,P3D);
}

void draw(){
translate(width/2, height/2, -depth/2);
rotateY(frameCount*PI/60);
rotateX(frameCount*PI/60);
}
for (float i=-depth/2+margin; i<=depth/2-margin; i+=boxSize){
pushMatrix();
for (float j=-height/2+margin; j<=height/2-margin; j+=boxSize){
pushMatrix();

for (float k=-width/2+margin; k<=width/2-margin; k+=boxSize){
  boxFill = color(abs(i), abs(j), abs(k), 50);
pushMatrix();
translate(k, j, i);
fill(boxFill);
box(boxSize, boxSize, boxSize);
popMatrix();
}
popMatrix();
}
popMatrix();
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

格子衫的從容 2025-02-07 06:18:26

我建议您先格式化您的代码:处理&gt;编辑&GT;自动格式(cmd+t/ctrl+t)

这将在rotatex()呼叫之后立即显示此错误:

缺少左卷曲括号“ {”

实际含义是您有一个额外的},它不应该是(因为 loop之后的应该是<代码> draw()函数:

float boxSize = 40;
float margin = boxSize*2;
float depth = 400;
color boxFill;

void setup() {
  size(500, 500, P3D);
}

void draw() {
  translate(width/2, height/2, -depth/2);
  rotateY(frameCount*PI/60);
  rotateX(frameCount*PI/60);

  for (float i=-depth/2+margin; i<=depth/2-margin; i+=boxSize) {
    pushMatrix();
    for (float j=-height/2+margin; j<=height/2-margin; j+=boxSize) {
      pushMatrix();

      for (float k=-width/2+margin; k<=width/2-margin; k+=boxSize) {
        boxFill = color(abs(i), abs(j), abs(k), 50);
        pushMatrix();
        translate(k, j, i);
        fill(boxFill);
        box(boxSize, boxSize, boxSize);
        popMatrix();
      }
      popMatrix();
    }
    popMatrix();
  }
}

I recommend formatting your code first: Processing > Edit > Auto Format (CMD+T / Ctrl+T)

This will reveal this error right after the rotateX() call:

Missing left curly bracket "{"

What it actually means is that you have an extra } and it shouldn't be (as the for loop after should be part of the draw() function:

float boxSize = 40;
float margin = boxSize*2;
float depth = 400;
color boxFill;

void setup() {
  size(500, 500, P3D);
}

void draw() {
  translate(width/2, height/2, -depth/2);
  rotateY(frameCount*PI/60);
  rotateX(frameCount*PI/60);

  for (float i=-depth/2+margin; i<=depth/2-margin; i+=boxSize) {
    pushMatrix();
    for (float j=-height/2+margin; j<=height/2-margin; j+=boxSize) {
      pushMatrix();

      for (float k=-width/2+margin; k<=width/2-margin; k+=boxSize) {
        boxFill = color(abs(i), abs(j), abs(k), 50);
        pushMatrix();
        translate(k, j, i);
        fill(boxFill);
        box(boxSize, boxSize, boxSize);
        popMatrix();
      }
      popMatrix();
    }
    popMatrix();
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文