处理IDE的显示出现问题,运行后,文本消失



IDK刚刚发生什么,但是当程序仍在运行时,文本显示它之后消失了,或者它只显示一个文本。 你们能帮我吗 对不起,我的英语不好,我将不胜感激你的帮助非常感谢 这是我的代码

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; 
}

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

void draw() { 
background(255);
// [...]
float [] x = new float [j];
float [] y = new float [j];

添加全局变量xydata。使用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; 
}

最新更新