We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Bubble [] bubbles;
void setup() {
size(1280,720);
smooth();
String[] data = loadStrings("data.txt");
bubbles = new Bubble[data.length];
for (int i = 0; i<bubbles.length; i++) {
float[] values = float(split(data[i],","));
bubbles[i] = new Bubble (values [0], values[1], values[2]); //change this value to display 46 values
}
println("values[0]");
}
void draw () {
background(255);
//display and move all bubbles
for(int i = 0; i < bubbles.length; i++) {
bubbles[i].display();
bubbles[i].drift();
}
bubbles[3].drift();
}
//A class to describe a "Bubble"
class Bubble {
float x,y;
float diameter;
float speed;
float r,g;
//the constructor intializes the color and size
//location is filled randomly
Bubble(float r_,float g_, float diameter_) {
x = random(width);
y = height;
r = r_;
g = g_;
diameter = diameter_;
}
//display the Bubble
void display() {
noStroke();
fill(r,g,255,150);
ellipse(x,y,diameter,diameter);
}
//move the bubble
void drift() {
y += random(-3,-0.1);
x += random(-1,1);
if(y < diameter*2) {
y = height + diameter*2;
}
}
}
My data file is this
90281, 19149, 90790, 19861, 91348, 20576, 91890, 21339, 92352, 22169, 92644, 23128, 92731, 24233, 92650, 25435, 92398, 26716, 91977, 28066, 91397, 29489, 90681, 30982, 89846, 32511, 88762, 34015, 87624, 35438, 86535, 36781, 85365, 38076, 84200, 39308, 13373, 83115, 40496, 12895, 82047, 41716, 80791, 42994, 79475, 44272, 78267, 45521, 77047, 46710, 75868, 47803, 74778, 48761, 73785, 49560, 72870, 50230, 72002, 50802, 71122, 51329, 70146, 51884, 69057, 52503, 67922, 53118, 66845, 53643, 65901, 53987, 65103, 54143, 64420, 54146, 63785, 54047, 63153, 53900, 62516, 53722, 61838, 53544, 61081, 53416, 60222, 53354, 59278, 53336, 58281, 53333, 57273, 53303,
please help me...
It too hard ; (
Answers
I am not sure if this is what you wanted but there are no errors, I modified your setup():
Edit: Note, this is what I used for data.txt:
90281, 19149, 90790, 19861, 91348, 20576, 91890, 21339, 92352, 22169, 92644, 23128, 92731, 24233, 92650, 25435, 92398, 26716, 91977, 28066, 91397, 29489, 90681, 30982, 89846, 32511, 88762, 34015, 87624, 35438, 86535, 36781, 85365, 38076, 84200, 39308, 13373, 83115, 40496, 12895, 82047, 41716, 80791, 42994, 79475, 44272, 78267, 45521, 77047, 46710, 75868, 47803, 74778, 48761, 73785, 49560, 72870, 50230, 72002, 50802, 71122, 51329, 70146, 51884, 69057, 52503, 67922, 53118, 66845, 53643, 65901, 53987, 65103, 54143, 64420, 54146, 63785, 54047, 63153, 53900, 62516, 53722, 61838, 53544, 61081, 53416, 60222, 53354, 59278, 53336, 58281, 53333, 57273, 53303, 56267, 53251
I wonder when it's red and green value and diameter
shouldn't the data.txt look like this:
etc. ?
As asimes said, this
works only when there are multiple lines in the text file (multiple paragraphs)
the data in one line are split by "," then
(or did the forum software corrupt the data you posted?)
Really thank you guys : ) it worked.
@ asimes It has no errors, but I think this code just visualizes the first line and that's it.
Yes, this doesn't change per Bubble (each gets 0, 1, and 2):
bubbles[i] = new Bubble(values[0], values[1], values[2])
;I didn't modify that line of code because I didn't understand what you wanted it to do.
Line 14 into the for-loop
data[i]
here; this has no txt file but has a string array instead.
But when the content of the txt file is as expected, it should work as well.
I expect the content of the txt files to be:
;-)