【问题标题】:problem the display of processing IDE, the after it run, the texts are gone处理IDE的显示问题,运行后,文本消失了
【发布时间】:2020-05-23 08:16:01
【问题描述】:

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

【问题讨论】:

    标签: processing processing-ide


    【解决方案1】:

    问题是数组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; 
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-21
      • 1970-01-01
      • 2021-06-21
      • 2018-08-31
      相关资源
      最近更新 更多