Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ArrayList<P> ps = new ArrayList<P>();
- public void setup() {
- size(600, 600);
- colorMode(HSB, 1, 1, 1, 1);
- for (int i = 0; i < 5000; i++) {
- ps.add(new P());
- }
- P seed = new P();
- seed.pos = new PVector(width / 2, height / 2);
- seed.alive = false;
- ps.add(seed);
- }
- public void draw() {
- background(0);
- for (P p : ps) {
- p.update();
- }
- for (P p : ps) {
- p.draw();
- }
- // if(frameCount<2000) saveFrame("/brownian/#####.jpg");
- }
- class P {
- float r = 5;
- boolean alive = true;
- int colorAtDeath = 0;
- PVector pos = new PVector(random(width), random(height));
- PVector spd = new PVector(0, r);
- void update() {
- if (alive) {
- //brownian motion
- spd.rotate(random(TWO_PI * 4));
- pos.add(spd);
- }
- //you're dead if you touch dead
- for (P p : ps) {
- if (p.alive || p.pos.equals(pos)) {
- continue;
- }
- float d = dist(p.pos.x, p.pos.y, pos.x, pos.y);
- if (d < r) {
- alive = false;
- if (colorAtDeath == 0) {
- colorAtDeath = color(frameCount / 1000f, 1, 1);
- }
- }
- }
- }
- void draw() {
- if (alive) {
- stroke(.5f);
- } else {
- stroke(colorAtDeath);
- }
- strokeWeight(r);
- point(pos.x, pos.y);
- }
- }
Add Comment
Please, Sign In to add comment