|
什么情况?……查不出错啊…………
Bubble[] bubbles;
void setup() {
size(800,600);
smooth();
// Load text file as an array of Strings
String [] data = loadStrings("data.txt");
// The size of the array of Bubble objects is determined by the total number of lines in the text file.
bubbles = new Bubble[data.length];
for (int i = 0; i < bubbles.length; i ++ ) {
// Each line is split into an array of floating point numbers.
float[] values = float(split(data[i], "," ));
// The values in the array are passed into the Bubble class constructor.
bubbles[i] = new Bubble(values[0],values[1]);
}
}
void draw() {
background(255);
translate(width/2,height/2);
// Display and move all bubbles
for (int i = 0; i < bubbles.length; i ++ ) {
bubbles[i].display();
// bubbles[i].drift();
if(i0){
stroke(0);
strokeWeight(2);
line(bubbles[i-1].r,bubbles[i-1].g,bubbles[i].r,bubbles[i].g);
}
}
} |
|