วันพุธที่ 12 พฤศจิกายน พ.ศ. 2557

try to load object (Balloon) data from text file using class Table

Balloon [] b = new Balloon [3];

void setup () {
  size (500, 500);
  int i =0;
  Table table;
  table = loadTable ("http://m.uploadedit.com/b042/1415780554347.csv", "header");

  for (TableRow row : table.rows ()) {
    int PosX = row.getInt ("PositionX");
    int PosY = row.getInt ("PositionY");
    int D = row.getInt ("Diameter");
    b[i] = new Balloon(PosX, PosY, D);
    i++;
  }
}
void draw () {
  background (0);
  for (int i=0; i<b.length; i++) {
    b[i].display();
    b[i].move_up();
  }
}

class Balloon {
  int x;
  int y;
  int r;

  Balloon (int x, int y, int r) {
    this.x = x;
    this.y = y;
    this.r = r;
  }

  void display () {
    fill (255, 255, 0);
    stroke(255);
    strokeWeight(3);
    line (this.x, this.y, this.x, this.y+(r*2));
    ellipse (this.x, this.y, this.r, this.r);
  }

  void move_up () {
    this.y = this.y -1;
    if (this.y <= 10) {
      this.y = height;
    }
  }
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น