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 me sorry for my bad English, I'll be appreciated your help thank you so much this is my code

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; 
 }
THe LaNd
  • 11
  • 2

1 Answers1

0

The issue is that the arrays x and y are recreated in every frame.

void draw() { 
 background(255);

 // [...]

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

Add global variables x, y and data. Use append() to add values to the arrays. And draw the text in a loop:

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; 
}
Rabbid76
  • 202,892
  • 27
  • 131
  • 174