currently your constructor initializes all the elements in the same way, with the same values, so your program is drawing all of them, but they are all drawn one on top of the other.
int total = 4;
ArrayList<Curly> plist = new ArrayList<Curly>();
float time = random(0, 1);
float size = random(300, 600);
PVector location = new PVector(random(-20, 20), random(-20, 20));
PVector velocity = new PVector (random(-.5, .5), random(-.5, .5));
float angle = velocity.heading();
void setup() {
size(1280, 1280);
for (int i = 0; i < total; i++) {
plist.add(new Curly(size, location, velocity, time+0.1*i, angle));
}
};
void draw() {
background(0);
noFill();
stroke(255);
for (int i = 0; i < plist.size(); i++) {
//println("the number is " + i);
Curly p = plist.get(i);
p.display();
}
//saveFrame("output/creatures_####.png");
};
class Curly{
float s;
PVector location;
Tail tail1;
Tail tail2;
Curly(float size, PVector loc, PVector vel, float t, float a){
s = size;
tail1 = new Tail(size, loc, vel, 1, t, a);
tail2 = new Tail(size, loc, vel, -1, t, a);
}
void display(){
resetMatrix();
//pushMatrix();
translate(width / 2, height / 2);
tail1.display();
//popMatrix();
resetMatrix();
//pushMatrix();
translate(width / 2, height / 2);
tail2.display();
//popMatrix();
}
};
class Tail{
float time = 0;
PVector velocity;
PVector location;
float maxspeed;
int steps;
float lineLength;
int sign;
float x;
float y;
float sizeWeight;
float angle;
float v_a;
float v_x;
float v_y;
Tail(float size, PVector loc, PVector vel, int s, float t, float a){ // acceleration, velocity
time = t;
lineLength = size;
location = loc;
steps = 300; // resolution
sign = s;
x = loc.x;
y = loc.y;
sizeWeight = size/1000;
angle = a;
v_a = 0.01;
v_x = vel.x;
v_y = vel.y;
}
void display(){
translate(x,y);
rotate(angle);
float segmentLength = (float) lineLength / steps;
float timeCurvature = (cos(time)+1) / 2.0;
for (int i = 0; i < steps; i++) { // i = 0
// O to 1 value indicating how far we are from the origin of the curve
float farFromOrigin = (float) i / (steps - 1);
strokeWeight((1 - farFromOrigin/1.5) * 3* sizeWeight + 2); // strokeWeight(3);//
// dividing into segments
line(0, 0, segmentLength, 0);
// Rotate the coordinate system (it keeps the rotations since we are not calling push/pop)
rotate(exp(farFromOrigin / 2.0) * timeCurvature * TWO_PI / (4*50.0 * (1 - farFromOrigin/1.5 + 0.1)));
// Then translate it
translate(sign*segmentLength, 0);
}
time += 0.01;
x = x + v_x;
y = y + v_y;
angle = angle + v_a;
};
};