English 中文(简体)
我不知道我手法Im试图让许多人去掉ug,但那是 t。
原标题:I don t know what wrong with my code I m try many to debug but it didn t run
  • 时间:2023-08-31 02:53:58
  •  标签:
  • processing
float [] x,y,d;

float [] vx,vy;

float [] x1,y1,d1;

float [] vx1,vy1;

void setup(){

size(800,800);

x = new float[5];

y = new float[5];

d = new float[5];

vx = new float[5];

vy = new float[5];

x1 = new float[5];

y1 = new float[5];

d1 = new float[5];

vx1 = new float[5];

vy1 = new float[5];

for(int i=0; i<5; i++){

x[i] = random(width);

y[i] = random(height);

d[i] = random(4);

x1[i] = random(width);

y1[i] = random(height);

d1[i] = random(4);

vx[i] = random(-10,10);

vy[i] = random(-10,10);

vx1[i] = random(-10,10);

vy1[i] = random(-10,10);

  }

}

void draw() {

 background(#0799E5);

 for(int i=0; i<5; i++){

 vichea(x[i], y[i], 5);

  vichea1(x1[i], y1[i], d1);

  x[i] += vx[i];

  y[i] += vy[i];

  x1[i] += vx1[i];

  y1[i] += vy1[i];

  if(x[i]>width  x[i]<0) {vx[i] = -vx[i]; }

  if(y[i]>width  y[i]<0) {vy[i] = -vy[i]; }

  if(x1[i]>width  x1[i]<0) {vx1[i] = -vx1[i]; }

  if(y1[i]>width  y1[i]<0) {vy1[i] = -vy1[i]; }

  

   } else if(i == 3) {

     x[i] = mouseX;

     y[i] = mouseY;

   }

   if (i<5) vichea(x[i], y[i], d[i]);

   else vichea1 (x1[i], y1[i], d1);

}

}

void keyPressed() {

  for(int i=0; i<5; i++){

    if (key ==  a ) x[i] -= 8;

    else if (key ==  d ) x[i] += 8;

    else if (key ==  w ) y[i] -= 8;

    else if (key ==  s ) y[i] += 8;

    else {

      x1[i] = mouseX;

      y1[i] = mouseY;

    }

  }

}

我不知道这有什么错误。

问题回答

它像你们的法典中有一些同义的错误和逻辑问题。 让我们一步步走,解决以下问题:

  1. 在<代码>draw(功能:

    • The conditions for checking if x[i] and y[i] are greater than width or less than 0 are incorrect. The correct syntax should be (x[i] > width || x[i] < 0).
    • The same correction needs to be applied to the conditions for checking y[i].
    • The else if(i == 3) block is not properly aligned and placed. It s outside the loop, and the correct indentation should be within the loop.
  2. 在<代码>draw()功能中,在条件<代码>(i<5) vichea(x[i], y[i], d[i];之后,你有一段额外的封闭式宽度。 应当消除这种污点。

  3. <代码>vichea (1x1[i], y1[i], d1); 不应排在外。 相反,它应当放在坡道内,在座标上,你目前正在打电话vichea(x[i], y[i], d[i];

  4. 在<代码>keyPressed()功能中,重新设置x1[i]y1[i]的栏目,如同在其他情况下一样,应当放在行文中。

页: 1

void setup() {
  // Your setup code remains the same
}

void draw() {
  background(#0799E5);
  
  for (int i = 0; i < 5; i++) {
    vichea(x[i], y[i], 5);
    vichea1(x1[i], y1[i], d1[i]);
    
    x[i] += vx[i];
    y[i] += vy[i];
    x1[i] += vx1[i];
    y1[i] += vy1[i];
    
    if (x[i] > width || x[i] < 0) { vx[i] = -vx[i]; }
    if (y[i] > width || y[i] < 0) { vy[i] = -vy[i]; }
    if (x1[i] > width || x1[i] < 0) { vx1[i] = -vx1[i]; }
    if (y1[i] > width || y1[i] < 0) { vy1[i] = -vy1[i]; }
    
    if (i == 3) {
      x[i] = mouseX;
      y[i] = mouseY;
    }
  }
}

void keyPressed() {
  for (int i = 0; i < 5; i++) {
    if (key ==  a ) x[i] -= 8;
    else if (key ==  d ) x[i] += 8;
    else if (key ==  w ) y[i] -= 8;
    else if (key ==  s ) y[i] += 8;
    else {
      x1[i] = mouseX;
      y1[i] = mouseY;
    }
  }
}

确保在作出这些更正后测试该守则。 如果你遇到任何进一步的问题或错误,可以自由地要求帮助!





相关问题
Best dynamic languages for OpenGL/general graphics

Which are the most mature and well supported solutions for writing graphical programs? I have been using C++ with OpenGL/GLUT, but would like to try a more flexible and expressive approach. Ruby and ...

How to change a GLSL shader parameter in Processing

I m playing with shaders in openGL using Processing. I m pretty noob at this and a bit lost. I found this thread that has an example on how to use GLSL shaders in Processing. I m just trying to the ...

How to tell when an @font-face rule is applied

Is there any way to tell when an @font-face rule is applied? I m creating @font-face rules that use data: URIs from a font file requested with an synchronous XMLHttpRequest in JavaScript and then ...

how to extrude a path in 3d?

I m trying to extrude a path in 3d. Nothing fancy yet, just following some points and using a regular polygon for tubing . I m using Processing for now to quickly prototype, but will later turn the ...

Java - Zoom / 3D Data Visualization Libraries

What are the best libraries/frameworks for doing 3D and/or Zoom interfaces in Java? I d like to be able to do some prototyping of creating new types of interfaces for navigating within data and ...

热门标签