2013年6月9日 星期日

第一支Processing for Android 程式

package processing.test.radiation;

import processing.core.*; 
import processing.data.*; 
import processing.event.*; 
import processing.opengl.*; 

import java.util.HashMap; 
import java.util.ArrayList; 
import java.io.File; 
import java.io.BufferedReader; 
import java.io.PrintWriter; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.io.IOException; 

public class Radiation extends PApplet {

String lines[]; 
String [][] radiation_csv;
int csvWidth=0;

public void setup() {
lines = loadStrings("http://www.aec.gov.tw/open/gammamonitor.csv");
background(255);
textSize(16);

for (int i=0; i < lines.length; i++) {
  String [] chars=split(lines[i],',');
  if (chars.length>csvWidth){
    csvWidth=chars.length;
  }
}


radiation_csv = new String [lines.length][csvWidth];


for (int i=0; i < lines.length; i++) {
  String [] temp = new String [lines.length];
  temp= split(lines[i], ',');
  for (int j=0; j < temp.length; j++){
      radiation_csv[i][j]=temp[j];
  }
}

}

public void draw() {
for (int i=1; i < lines.length; i++) {
   fill(0, 102, 153, 204);
   text(radiation_csv[i][1]+" "+radiation_csv[i][2]+" (mSv/hr)",10,20+i*15);
   stroke(255, 0, 0);
   line(200, 20+i*15, 200+PApplet.parseFloat(radiation_csv[i][2])*2000, 20+i*15);

  }

}

  public int sketchWidth() { return 800; }
  public int sketchHeight() { return 800; }
}

沒有留言:

張貼留言