Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. // dimensions
  2. int dim = 250;
  3. int num = 1000;
  4. int time = 0;
  5. boolean mousedown = false;
  6. int count =0;
  7. int initThick = 3;
  8. float lastX;
  9. float lastY;
  10. // object array
  11. Particle[] particles;
  12. // initialization
  13. void setup() {
  14.   size(500,500,P3D);
  15. //  size(dim,dim,P3D);
  16.   ellipseMode(CENTER_RADIUS);
  17.   background(255);
  18.   frameRate(30);
  19.   // make some discs
  20.   particles = new Particle[num];
  21.   // arrange in anti-collapsing circle
  22.   for (int i=0;i<num;i++) {
  23.     particles[i] = new Particle(0,0,0,0,0);
  24.   }
  25. }
  26. void draw() {
  27.   for (int c=0;c<num;c++) {
  28.     Particle p = particles[c];
  29.     p.move();
  30.     p.draw();
  31.   }
  32.   time++;
  33. }
  34. void mousePressed() {
  35.   background(255);
  36.   for (int i=0;i<num;++i) {
  37.     particles[i] = new Particle(0,0,0,0,0);
  38.   }
  39.   mousedown = true;
  40.   lastX = mouseX;
  41.   lastY = mouseY;
  42. }
  43. void mouseReleased() {
  44.   mousedown = false;
  45. }
  46. void mouseDragged() {
  47.   for (int i=0;i<100;i+=2) {
  48.     float xx = (mouseX-lastX)*i/100+lastX;
  49.     float yy = (mouseY-lastY)*i/100+lastY;
  50.     stroke(0);
  51.     fill(0);
  52.     rect(xx-initThick/2,yy-initThick/2,initThick,initThick);
  53.   }
  54.   if (random(100)>50) {
  55.     float rr = atan2(mouseY-lastY,mouseX-lastX);
  56.     float ss = sqrt(pow(mouseX-lastX,2)+pow(mouseY-lastY,2));
  57.     particles[count] = new Particle(mouseX,mouseY,rr,ss,initThick-1);
  58.     count++;
  59.     if (count==num) {
  60.       count = 0;
  61.     }
  62.   }
  63.   lastX = mouseX;
  64.   lastY = mouseY;
  65. }
  66. class Particle {
  67.   float x,y;
  68.   float r,s;
  69.   float f;
  70.   float t;
  71.   Particle(float X, float Y, float R, float S, float T) {
  72.     x=X;
  73.     y=Y;
  74.     r=R;
  75.     s=S;
  76.     t=T;
  77.   }
  78.   void move() {
  79.     x += cos(r)*s;
  80.     y += sin(r)*s;
  81.     r += random(-.1,.1)*PI;
  82.     s*=.96;
  83.   }
  84.   void draw() {
  85.     noStroke();
  86.     fill(0);
  87.     rect(x-t/2,y-t/2,t,t);
  88.     if (t>1 && random(100)>80) {
  89.       particles[count] = new Particle(x,y,r,s*random(1),t-1);
  90.       count ++;
  91.       if (count==num) {
  92.         count=0;
  93.       }
  94.     }
  95.   }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement