处理IDE的显示问题,运行后,文字不见了。

问题描述 投票:1回答:1

IDK what just happen, but when the program is still running, the text the after it showed it gone, or it just showed one text.Can u guys help mesorry for my bad English, I'll be appreciated your help thank you so much 这是我的代码。

int j;
float timeinterval;
float lasttimecheck;
float endY = 0;
int index = 0;
int x2;
int y2;
int x0=150;
int y0=0;
float r = random(1, 20);
float x1 = 1;
float y1 = 1;
String[] words;

void timecapture() {
  lasttimecheck = millis();
  timeinterval = 0; //2sec
}

void setup() {
  size (400, 400);
  timecapture();
  frameRate(5);
   stroke(0);
}

void draw() { 
  background(255);

  textSize(20);
  int y2 = 0; 
  float [] x = new float [j];
  float [] y = new float [j];


  for (int i = 0; (i<x.length) && (i<y.length); i++ ) {
    x[i] = x1;
    y[i] = y1;
    fill(0);
    //text (x[i]+","+y[i], 20, y1);
  }

  y2 = y2+40;

  String[] data = new String[x.length];
  for (int ii = 0; ii<x.length; ii++) {
    data [ii] = str(x[ii]) + ("\t") + str(y[ii]);
  }
  if (millis() > lasttimecheck + timeinterval) {
    saveStrings("location", data);
    lasttimecheck = millis();
  }
    if (x.length<30 && y.length<30)
    j=j+1;
    x1=x1+r; y1=y1+r; 
 }
processing processing-ide
1个回答
0
投票

问题是,数组 xy 在每一帧中都会重新创建。

void draw() { 
 background(255);

 // [...]

 float [] x = new float [j];
 float [] y = new float [j];

添加全局变量 x, ydata. 使用 append() 向数组中添加值。并在循环中绘制文本。

float [] x = new float [0];
float [] y = new float [0];
String[] data = new String[0];

void draw() { 
    background(255);

    textSize(20);
    for (int i = 0; (i<x.length) && (i<y.length); i++ ) {
        fill(0);
        text (x[i]+","+y[i], 20, i*20 + 20);
    }

    if (x.length <= j) { 
        x = append(x, x1);
        y = append(y, y1);
        data = append(data, str(x1) + ("\t") + str(y1));
    }

    if (millis() > lasttimecheck + timeinterval) {
        saveStrings("location", data);
        lasttimecheck = millis();
    }

    if (x.length<30 && y.length<30) {
        j=j+1;
    }
    x1=x1+r; y1=y1+r; 
}
© www.soinside.com 2019 - 2024. All rights reserved.