103




int num = 800;
ArrowParticle[] p = new ArrowParticle[num];
float radius = 1.2;

void setup(){
size(600,300);
smooth();
for(int i = 0; i float velX = random(-3.0,3.0);
float velY = random(-4.0,-2.0);
p[i] = new ArrowParticle(width/2,80,velX,velY,1.2);
}
}

void draw(){
background(0);
for(int i = 0; i < p.length; i++){
p[i].update();
p[i].regenerate();
p[i].display();
}
}

class LimitedParticle extends Particle{
float friction = 0.99;
LimitedParticle(int x, int y, float vx, float vy, float radius,float friction){
super(x,y,vx,vy,radius);
this.friction = friction;
}
void update(){
vy*=friction;
vx *= friction;
super.update();
limit();
}
void limit(){
if(y>height-radius){
vy =-vy;
y = constrain(y,-height*height,height-radius);
}
if((x < radius)||(x >width-radius)){
vx = -vx;
x = constrain(x,radius,width-radius);
}
}
}

class Particle{
float x,y;
float vx,vy;
float radius;
float gravity = 0.1;
Particle(int x,int y,float vx, float vy, float radius){
this.x = x;
this.y = y;
this.vx = vx;
this.vy = vy;
this.radius = radius;
}

void update(){
vy = vy + gravity;
y += vy;
x += vx;
}
void display(){
ellipse(x,y,radius*2,radius*2);
}
}

コメント