使用Pjs处理不能在html中工作

时间:2013-10-17 20:45:59

标签: processing processing.js

我不知道麻烦是什么。它正在阅读csv,它甚至可以绘制点,但不是在正确的位置!这是它当前显示的内容(注意点如何排列在垂直线上,而不是相对于我的csv文件中的最大/最小纬度/经度坐标进行映射!):www.fuhqu.com/testgps.html

float xMax, xMin, yMax, yMin;
Writedot [] writedot = new Writedot[1];

void setup()
{
  size(1000, 600);
  frameRate(30);
  String lines[] = loadStrings("myData258.csv"); 
  for (int i=0; i < lines.length; i++) {
    String [] chars=split(lines[i], ',');
    yMax = max(yMax, float(chars[0]));
    yMin = min(yMin, float(chars[0]));
    xMax = max(xMax, float(chars[1]));
    xMin = min(xMin, float(chars[1]));
  }

  for (int i=0; i < lines.length; i++) { 
    String [] chars=split(lines[i], ','); 
    float lat = float(chars[0]);
    float lon = float(chars[1]);

    float mapx = map(lon, xMin, xMax, 0+50, width-50);
    float mapy = map(lat, yMin, yMax, 0+50, height-50);

    Writedot b = new Writedot(mapx, mapy);
    writedot = (Writedot[]) append(writedot, b);
  }
}

void draw () {
  background(#000000);
  for (int i = 1; i < writedot.length; i++) {
    writedotNew[i].move();
    writedotNew[i].display();
  }
}

class Writedot {
  float xpos;
  float ypos;
  int trans =0;
  boolean countonoff = true;

  Writedot (float temp_xpos, float temp_ypos) {
    xpos = temp_xpos;
    ypos = temp_ypos;
  }

  void display() {
    stroke (0);
    fill(trans, random(30, 255)); 
    pushMatrix();
    ellipse (xpos, ypos, 4, 4);
    popMatrix();
  }

  void move() {
    if (countonoff) {
      trans+=5;
      if (trans == 255) {
        countonoff = false;
      }
    }
    else {
      trans-=5;
      if (trans == 100) {
        countonoff = true;
      }
    }
  }
}

0 个答案:

没有答案