class particleBall
{
particle[] Particles = new particle[NUM_PARTICLES];
particleBall()
{
for(int i = 0; i < NUM_PARTICLES; i++)
{
float theta = random(0,TWO_PI);
float u = random(-1,1);
Particles[i] = new particle(theta,u);
}
}
void update()
{
for(int i = 0; i < NUM_PARTICLES; i++)
{
Particles[i].update();
}
}
void render()
{
fill(20,20,20,255);
sphereDetail(40);
sphere(radius-10);
sphereDetail(5);
fill(150,222,45,50);
for(int i = 0; i < NUM_PARTICLES; i++)
{
Particles[i].render();
}
}
}
//import java.awt.event.*;
int NUM_PARTICLES = 3000;
particleBall ParticleBall;
float startingRadius = 100, radius = 150;
int centerX, centerY;
boolean mouseDown = false;
void setup()
{
size(800,800,P3D);
//frame.addMouseWheelListener(new MouseWheelInput());
ParticleBall = new particleBall();
noStroke();
sphereDetail(8);
frameRate(30);
}
void draw()
{
background(50);
camera(0,0,500, 0,0,0, 0,1,0);
if(mouseDown)
{
radius = startingRadius + centerX-mouseX;
}
pushMatrix();
rotateY(map(mouseX,0,width,0,TWO_PI));
rotateX(map(mouseY,0,height,0,TWO_PI));
fill(150,222,45, 50);
ParticleBall.update();
ParticleBall.render();
popMatrix();
}
void mousePressed()
{
mouseDown = true;
centerX = mouseX;
centerY = mouseY;
}
void mouseReleased()
{
mouseDown = false;
}
/*
class MouseWheelInput implements MouseWheelListener
{
void mouseWheelMoved(MouseWheelEvent e)
{
int step=e.getWheelRotation();
radius+=step*10;;
}
}*/
class particle
{
float theta, u;
float vTheta, vU;
float x,y,z;
particle(float Theta, float U)
{
theta = Theta;
u = U;
vTheta = 0;
vU = 0;
}
void update()
{
vTheta+=random(-0.001,0.001);
theta+=vTheta;
if(theta<0||theta>TWO_PI)
{
vTheta*=-1;
}
vU+=random(-0.001,0.001);
u+=vU;
if(u<-1||u>1)
{
vU*=-1;
}
vU*=0.95;
vTheta*=0.95;
x = radius*cos(theta)*sqrt(1-(u*u));
y = radius*sin(theta)*sqrt(1-(u*u));
z = u*radius;
}
void render()
{
pushMatrix();
translate(x,y,z);
box(2);
//sphere(2);
popMatrix();
}
}