80


import processing.opengl.*;


int num = 80;
LimitedParticle[] p = new LimitedParticle[num];
float radius = 2.6;
void setup() {
size(640, 480,OPENGL);

noStroke();
smooth();
for (int i = 0; i < p.length; i++) {
float velX = random(-4, 4);
float velY = random(-10, 0);
float velZ = random(100);
color col = color(random(255,200),random(255,200),random(255,200));
p[i] = new LimitedParticle(width/2, height/2, -100,velX, velY,velZ, random(5), 0.999,col);
}
}
void draw() {
lights();
ambientLight(255,255,255);
directionalLight(255, 255, 255, -1, 0, 0);
fill(255, 24);
rect(0, 0, width, height);
fill(255);
for (int i = 0; i < p.length; i++) {

p[i].update();
p[i].display();
}
}

void mousePressed(){
save("80.jpg");
}

class LimitedParticle extends Particle{
float friction = 0.99;
color col;
LimitedParticle(int x, int y,int z, float vx, float vy,float vz, float radius, float friction, color col){
super(x,y,z,vx,vy,vz,radius);
this.friction = friction;
this.col = col;
}
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 <> width-radius)){
vx = -vx;
x = constrain(x,radius,width-radius);
}
}
void display(){
fill(col);
super.display();
}
}

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

void update(){
vy = vy + gravity;
y += vy;
x += vx;
z += vz;
}
void display(){
pushMatrix();
translate(x,y);
sphere(radius*2);
popMatrix();

}
}

コメント