Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 我的程序正在向后存储数组_Arrays_Processing_Record - Fatal编程技术网

Arrays 我的程序正在向后存储数组

Arrays 我的程序正在向后存储数组,arrays,processing,record,Arrays,Processing,Record,我正在用一个叫做“处理”的程序来写这段代码。当你拖动鼠标时,代码应该在数组中记录鼠标坐标,然后当你释放鼠标时,它会显示一个圆圈,沿着数组中存储的坐标路径,但现在它播放从我停止拖动鼠标到我开始拖动的圆圈。这应该是另一种方式,但我已经尝试了很多相反的方式,但我所做的似乎都不起作用:/ 如果你能给我看看,那真的很有帮助!我肯定我错过了一些非常明显的东西 int num = 100; int[] x = new int[num]; int[] y = new int[num]; boolean rele

我正在用一个叫做“处理”的程序来写这段代码。当你拖动鼠标时,代码应该在数组中记录鼠标坐标,然后当你释放鼠标时,它会显示一个圆圈,沿着数组中存储的坐标路径,但现在它播放从我停止拖动鼠标到我开始拖动的圆圈。这应该是另一种方式,但我已经尝试了很多相反的方式,但我所做的似乎都不起作用:/

如果你能给我看看,那真的很有帮助!我肯定我错过了一些非常明显的东西

int num = 100;
int[] x = new int[num];
int[] y = new int[num];
boolean released = false;
int arrayIndex;
boolean drag = false;

void setup() {
  size(600, 600);
  noStroke();
  smooth();
  fill(255, 102);
}

void draw() {
  background(0);
  if (released==true){
      arrayIndex= (arrayIndex+1)%100;
      ellipse(x[arrayIndex],y[arrayIndex],20,20);  

  }

}


void mouseDragged(){
  drag=true;
  x[0] = mouseX;
  y[0] = mouseY;
  for (int i = num - 1; i > 0; i--) {
    x[i] = x[i-1];
    y[i] = y[i-1];
  }



}

void mouseReleased(){
 released=true;
}

正如你们所指出的,你们从一端到另一端添加坐标,并从头到尾阅读表格。因此,使用
帧数
或中间变量反转显示迭代,eithr

使用帧数:

int num = 100;
int[] x = new int[num];
int[] y = new int[num];
boolean released = false;
int arrayIndex;
boolean drag = false;

void setup() {
  size(600, 600);
  noStroke();
  smooth();
  fill(255, 102);
}

void draw() {
  background(0);
  if (released==true){
      arrayIndex= (num-1) - (frameCount+1)%100;
      ellipse(x[arrayIndex],y[arrayIndex],20,20);  

  }

}


void mouseDragged(){
  drag=true;
  x[0] = mouseX;
  y[0] = mouseY;
  for (int i = num - 1; i > 0; i--) {
    x[i] = x[i-1];
    y[i] = y[i-1];
  }



}

void mouseReleased(){
 released=true;
}
使用另一个变量:

int num = 100;
int[] x = new int[num];
int[] y = new int[num];
boolean released = false;
int arrayIndex;
boolean drag = false;

void setup() {
  size(600, 600);
  noStroke();
  smooth();
  fill(255, 102);
}

void draw() {
  background(0);
  if (released==true){
      arrayIndex= (arrayIndex+1)%100;
      int reversed = (num-1) - arrayIndex; 
      ellipse(x[reversed],y[reversed],20,20);  

  }

}


void mouseDragged(){
  drag=true;
  x[0] = mouseX;
  y[0] = mouseY;
  for (int i = num - 1; i > 0; i--) {
    x[i] = x[i-1];
    y[i] = y[i-1];
  }



}

void mouseReleased(){
 released=true;
}

如果你用你正在使用的语言给它加上标签,这会有所帮助。在我看来,您似乎是在向数组中添加值,从顶部开始向下,而读取数组以绘制路径的代码从底部开始向上。@MikeW
Processing
是该语言的名称,它是一个java框架。谢谢老兄!!我现在看到了:)