xxxxxxxxxx
int row =5, cal=13;
Ball inRow_Cll[][] = new Ball[row-1][cal-1];
Line ballLine = new Line();
ArrayList<Particle> p = new ArrayList<Particle>();
void setup() {
size(screenWidth, screenHeight);
creatBall();
}
void creatBall() {
int posX = width/row;
int posY = height/cal;
for (int i = 1; i < row; i++) {
for (int j = 1; j < cal; j++) {
inRow_Cll[i-1][j-1]=(new Ball(posX*i, posY*j));
}
}
}
void draw() {
background(0);
ballLine.display();
for (int i = 0; i < row-1; i++ ) {
for (int j = 0; j < cal-1; j++ ) {
inRow_Cll[i][j].display();
}
}
}
class Ball {
PVector location;
float ballSize = 30;
Ball(int x, int y) {
location = new PVector(x, y);
for (int i=0; i < cal-1; i++) {
p.add( new Particle(new PVector(x, y)));
}
}
void display() {
strokeWeight(4);
stroke(255, 255);
fill(0);
ellipse(location.x, location.y, ballSize, ballSize);
}
}
class Line {
int glowLine, threshold = 7000;
long timer, oldTime;
int numOFball = ((row-1) * (cal-1)) -cal;
Line() {
}
void display() {
for (int i = 0; i < row-2; i++ ) {
for (int j = 0; j < cal-1; j++ ) {
for ( int k= 0; k< cal-1; k++) {
stroke(240, 150, 0,100);
strokeWeight(2);
//if ((cal-1) * i + j == glowLine) {
// stroke(255, 100, 10, 255);
//}
line(inRow_Cll[i][j].location.x, inRow_Cll[i][j].location.y, inRow_Cll[i+1][k].location.x, inRow_Cll[i+1][k].location.y);
Particle tempP = p.get((cal-1)*((cal-1) * i + j) +k);
tempP.move(tempP.mLoc, inRow_Cll[i+1][k].location);
}
}
}
update();
}
void update() {
timer = millis();
if (timer - oldTime > threshold) {
oldTime = timer;
glowLine+=1;
int counter=0;
for (int i = 0; i < row-1; i++ ) {
for (int j = 0; j < cal-1; j++ ) {
for (int h = 0; h < cal-1; h++ ) {
PVector tempL = new PVector(inRow_Cll[i][j].location.x, inRow_Cll[i][j].location.y);
Particle tempP = p.get(counter);
counter++;
tempP.restLoc(tempL);
}
}
}
if (glowLine >= numOFball) {
glowLine = 0;
}
}
}
}
class Particle {
PVector mLoc;
PVector mDir;
float mVel;
float mRadius;
Particle(PVector loc) {
mLoc = loc;
mDir = new PVector(1, 1);
mVel = 5;
mRadius = 8;
}
void draw() {
// stroke(240, 150, 0);
// strokeWeight(1);
noStroke();
fill(255, 255, 0);
ellipse(mLoc.x, mLoc.y, mRadius, mRadius);
}
void restLoc(PVector loc) {
mLoc = loc;
mDir = new PVector(1, 1);
}
void move(PVector p1, PVector p2) {
this.update();
PVector pTemp = new PVector(p2.x, p2.y);
pTemp.sub(p1);
pTemp.normalize();
mDir = pTemp;
this.draw();
}
void update() {
PVector tempDir = new PVector(mDir.x, mDir.y);
tempDir.mult(mVel);
mLoc.add(tempDir);
}
}