public class Mass
{
float x,y,mass;
color col;
boolean ALIVE=true;
Mass()
{
x=random(0,width);
y=random(0,height);
mass=random(-1000,1000);
colorMode(HSB);
col=color(random(0,255),random(120,200),random(90,210));
}
Mass(float tmass)
{
x=random(0,width);
y=random(0,height);
mass=tmass;
//colorMode(HSB);
//col=color(random(0,255),random(120,200),random(90,210));
col=color(200,0,0,30);
}
Mass(float tmass,color tcol)
{
x=random(0,width);
y=random(0,height);
mass=tmass;
colorMode(RGB);
col=tcol;
}
void draw()
{
if (mass>1||mass<1)
{/*
//fill(col);
//noStroke();
noFill();
stroke(col);
strokeWeight(.6);
ellipse(x,y,10,10);*/
}
else
{
strokeWeight(.6);
stroke(col);
point(x,y);
}
}
void calculate(float tx,float ty,float tmass)
{
float distance=dist(tx,ty,x,y);
{
float masss=(distance<=15)?tmass/(16-distance):tmass;
//float force=-50*masss/pow(distance,2);
float force=-masss/pow(distance,1.1);
x=x+force*sin(atan2(tx-x,ty-y));
y=y+force*cos(atan2(tx-x,ty-y));
if (x>width||x<0||y>height||y<0||distance<10) ALIVE=false;
}
}
}
ArrayList masses;
ArrayList smalls;
int colh;
void setup()
{
size(600,600,P3D);
background(0);
smooth();
frameRate(30);
masses = new ArrayList();
for (int i=0;i<20;i++)
{
//masses.add(new Mass(random(-1000,1000)));
masses.add(new Mass(random(0,1000)));
}
smalls=new ArrayList();
for (int i=0;i<300;i++)
{
//colorMode(RGB);
//smalls.add(new Mass(1,color(255,255,255)));
colorMode(HSB);
smalls.add(new Mass(1,color(random(0,45),random(180,240),random(90,210))));
}
}
void draw()
{
/*background(0,10);
fill(0,1);
rect(0,0,width,height);*/
for (int i=masses.size()-1;i>=0;i--)
{
Mass mass=(Mass) masses.get(i);
Mass small;
for (int k=smalls.size()-1;k>=0;k--)
{
small=(Mass) smalls.get(k);
small.calculate(mass.x,mass.y,mass.mass);
if (!small.ALIVE)
{
//println(small.x+" "+small.y+" "+small.ALIVE+" "+smalls.size());
println(smalls.size());
smalls.remove(k);
colorMode(HSB);
smalls.add(new Mass(1,color(random(0,45),random(180,240),random(90,210))));
}
else small.draw();
}
mass.draw();
}
}
void mousePressed()
{
for (int k=masses.size()-1;k>=0;k--)
{
masses.remove(k);
}
for (int i=0;i<20;i++)
{
//masses.add(new Mass(random(-1000,1000)));
masses.add(new Mass(random(0,1000)));
}
background(0);
}
void keyPressed()
{
if (key=='R'||key=='r')
{
for (int k=masses.size()-1;k>=0;k--)
{
masses.remove(k);
}
for (int i=0;i<20;i++)
{
//masses.add(new Mass(random(-1000,1000)));
masses.add(new Mass(random(0,1000)));
}
background(0);
}
}