Skip to content

Instantly share code, notes, and snippets.

@KrabCode
Last active July 26, 2019 14:56
Show Gist options
  • Select an option

  • Save KrabCode/c490e380c27bcf6213631ff899e5acf2 to your computer and use it in GitHub Desktop.

Select an option

Save KrabCode/c490e380c27bcf6213631ff899e5acf2 to your computer and use it in GitHub Desktop.
ArrayList<P> ps = new ArrayList<P>();
ArrayList<P> psBin = new ArrayList<P>();
int startBuffer = 4000;
int birthDistanceFromCamera = 3000;
void setup() {
size(800, 800, P3D);
//fullScreen(P3D);
for (int i = 0; i < startBuffer; i++) {
animate(i);
}
}
void draw() {
animate(2*frameCount+startBuffer);
if (frameCount > 100 && frameCount < 820) {
//saveFrame("C://capture/2/####.jpg");
}
}
void animate(float t) {
background(0);
translate(width*.5, height*.5, t);
ps.add(new P(
randomGaussian()*width,
randomGaussian()*height,
-t-birthDistanceFromCamera
));
updatePs(t);
}
void updatePs(float t) {
for (P p : ps) {
p.update(t);
if (p.dead) {
psBin.add(p);
}
}
ps.removeAll(psBin);
psBin.clear();
println(ps.size());
}
class P extends PVector {
boolean dead = false;
int born = frameCount;
int fadeIn = 30;
float weight = 2+randomGaussian();
P(float x, float y, float z) {
super(x, y, z);
}
void update(float t) {
float fadeInNormalized = map(frameCount, born, born + fadeIn, 0, 1);
stroke(255*fadeInNormalized);
strokeWeight(weight);
point(x, y, z);
if (z-1000 > -t) {
dead = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment