Guest User

Untitled

a guest
Dec 17th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. ArrayList<P> ps = new ArrayList<P>();
  2.  
  3. public void setup() {
  4. size(600, 600);
  5. colorMode(HSB, 1, 1, 1, 1);
  6. for (int i = 0; i < 5000; i++) {
  7. ps.add(new P());
  8. }
  9. P seed = new P();
  10. seed.pos = new PVector(width / 2, height / 2);
  11. seed.alive = false;
  12. ps.add(seed);
  13. }
  14.  
  15. public void draw() {
  16. background(0);
  17. for (P p : ps) {
  18. p.update();
  19. }
  20. for (P p : ps) {
  21. p.draw();
  22. }
  23. // if(frameCount<2000) saveFrame("/brownian/#####.jpg");
  24. }
  25.  
  26. class P {
  27. float r = 5;
  28. boolean alive = true;
  29. int colorAtDeath = 0;
  30. PVector pos = new PVector(random(width), random(height));
  31. PVector spd = new PVector(0, r);
  32.  
  33. void update() {
  34. if (alive) {
  35. //brownian motion
  36. spd.rotate(random(TWO_PI * 4));
  37. pos.add(spd);
  38. }
  39.  
  40. //you're dead if you touch dead
  41. for (P p : ps) {
  42. if (p.alive || p.pos.equals(pos)) {
  43. continue;
  44. }
  45. float d = dist(p.pos.x, p.pos.y, pos.x, pos.y);
  46. if (d < r) {
  47. alive = false;
  48. if (colorAtDeath == 0) {
  49. colorAtDeath = color(frameCount / 1000f, 1, 1);
  50. }
  51. }
  52. }
  53. }
  54.  
  55. void draw() {
  56. if (alive) {
  57. stroke(.5f);
  58. } else {
  59. stroke(colorAtDeath);
  60. }
  61. strokeWeight(r);
  62. point(pos.x, pos.y);
  63. }
  64. }
Add Comment
Please, Sign In to add comment