//Code voor Regen en Onweer

int direction;
RainGravity g[];
int Num = 100;
float a = 0.1;

void setup(){
size(1000,1000);
g = new RainGravity[Num];
PVector _velocity = new PVector(0,5);
for(int i=0;i<Num;i++){
float x = random(width);
float y = random(-1000,0);
//インスタンスを配列で管理 ポリモーフィズムの実現
g[i] = new RainGravity(x,y,_velocity,1.0);
}
}

void draw(){
background(0);
//3%の確率で雷
float t = random(0,100);
if(t>97){
background(255);
}

for(int j=0;j<Num;j++){
g[j]._gravity();
g[j].move();
}
}

//Gravity クラスの定義
class Gravity{
float x,y,gravity,diameter;
PVector velocity;
float direction = 0.5;

Gravity(float x,float y,PVector velocity,float gravity) {
this.x = x;
this.y = y;
this.velocity = velocity;
this.gravity = gravity;
}

void _gravity(){
velocity.y += a;
y += (velocity.y * direction);
x += (velocity.x * direction);
if(y>height){
y = random(-500,0);
velocity.y = 5;
}
}
void move(){
this.move((int)this.x,(int)this.y);
}

void move(int x,int y){
background(0);
ellipse(x,y,10,10);
}

}
//Gravity クラスの継承

class RainGravity extends Gravity{
float diamiter;
RainGravity(float x,float y,PVector velocity,float gravity){
super(x,y,velocity,gravity);
}
void _gravity(){
super._gravity();
}

void move(){
this.move((int)this.x,(int)this.y);
}

void move(int x,int y){
fill(0,0,255);
ellipse(x,y,10,10);
}
}