Code:class Particle
{
float x, y;
float speedx, speedy;
float speed;
float mass;
color c;
Particle(float tempx, float tempy, float tempspeed, float tempmass)
{
x = tempx;
y = tempy;
speed = tempspeed;
mass = tempmass;
c = color(random(225), random(225), random(225));
}
void display()
{
fill(c);
noStroke();
ellipse(x, y, mass, mass);
}
void move()
{
speedx = speedx+((random(1)-0.5)*speed);
speedy = speedy+((random(1)-0.5)*speed);
x = x + speedx;
y = y + speedy;
}
}
Particle[] particles;
void setup()
{
size(200, 200);
particles = new Particle[0];
}
void draw()
{
background(0);
particles = append(particles, new Particle(mouseX, mouseY, 1, 20));
for(int i = 0; i < particles.length; i++)
{
particles[i].display();
particles[i].move();
}
}
I'm getting an error with the line that uses the append function.
What am I doing wrong here? The error I'm getting:
Code:
Cannot convert from Object to sketch_dec11a.Particle[]
It doesn't matter whether I use append or splice.
I want to make an array of objects that gets bigger every frame, so that I can access the functions in them that make them move and display. If there's a more efficient way to do all this, I'd appreciate knowing it.