Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // dimensions
- int dim = 250;
- int num = 1000;
- int time = 0;
- boolean mousedown = false;
- int count =0;
- int initThick = 3;
- float lastX;
- float lastY;
- // object array
- Particle[] particles;
- // initialization
- void setup() {
- size(500,500,P3D);
- // size(dim,dim,P3D);
- ellipseMode(CENTER_RADIUS);
- background(255);
- frameRate(30);
- // make some discs
- particles = new Particle[num];
- // arrange in anti-collapsing circle
- for (int i=0;i<num;i++) {
- particles[i] = new Particle(0,0,0,0,0);
- }
- }
- void draw() {
- for (int c=0;c<num;c++) {
- Particle p = particles[c];
- p.move();
- p.draw();
- }
- time++;
- }
- void mousePressed() {
- background(255);
- for (int i=0;i<num;++i) {
- particles[i] = new Particle(0,0,0,0,0);
- }
- mousedown = true;
- lastX = mouseX;
- lastY = mouseY;
- }
- void mouseReleased() {
- mousedown = false;
- }
- void mouseDragged() {
- for (int i=0;i<100;i+=2) {
- float xx = (mouseX-lastX)*i/100+lastX;
- float yy = (mouseY-lastY)*i/100+lastY;
- stroke(0);
- fill(0);
- rect(xx-initThick/2,yy-initThick/2,initThick,initThick);
- }
- if (random(100)>50) {
- float rr = atan2(mouseY-lastY,mouseX-lastX);
- float ss = sqrt(pow(mouseX-lastX,2)+pow(mouseY-lastY,2));
- particles[count] = new Particle(mouseX,mouseY,rr,ss,initThick-1);
- count++;
- if (count==num) {
- count = 0;
- }
- }
- lastX = mouseX;
- lastY = mouseY;
- }
- class Particle {
- float x,y;
- float r,s;
- float f;
- float t;
- Particle(float X, float Y, float R, float S, float T) {
- x=X;
- y=Y;
- r=R;
- s=S;
- t=T;
- }
- void move() {
- x += cos(r)*s;
- y += sin(r)*s;
- r += random(-.1,.1)*PI;
- s*=.96;
- }
- void draw() {
- noStroke();
- fill(0);
- rect(x-t/2,y-t/2,t,t);
- if (t>1 && random(100)>80) {
- particles[count] = new Particle(x,y,r,s*random(1),t-1);
- count ++;
- if (count==num) {
- count=0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement