Advertisement
xeromino

code

Feb 15th, 2016
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. var particles = [];
  2. var bg = "#202020";;
  3.  
  4. function setup() {
  5.   createCanvas(540, 540);
  6.   colorMode(HSB, 360, 1, 1);
  7. }
  8.  
  9. function draw() {
  10.   background(bg);
  11.   for (var i = 0; i < particles.length; i++) {
  12.     particles[i].update();
  13.     particles[i].paint();
  14.   }
  15. }
  16.  
  17. function mousePressed() {
  18.   particles.push(new Particle(mouseX, mouseY));
  19. }
  20.  
  21. function keyPressed() {
  22.   saveFrames("anim/image-", "png", 5, 30);
  23. }
  24.  
  25. function Particle(x, y) {
  26.   this.x = x;
  27.   this.y = y;
  28.   this.history = [];
  29.   this.baseCol = random(360);
  30.   var maxParts = 25; //, n = frameCount;
  31.  
  32.   this.update = function() {
  33.     var r = 10;
  34.     this.x += random(-r, r);
  35.     this.y += random(-r, r);
  36.     /* var nx = map(noise((n+frameCount)/1),0,1,-r,r);
  37.     var ny = map(noise((2*n+frameCount)/1),0,1,-r,r);
  38.     this.x += nx;
  39.     this.y += ny;
  40.     */
  41.     var v = createVector(this.x, this.y);
  42.     this.history.push(v);
  43.     if (this.history.length > maxParts) {
  44.       this.history.splice(0, 1);
  45.     }
  46.   }
  47.  
  48.   this.paint = function() {
  49.     for (var i = 0; i < this.history.length; i++) {
  50.       var sz = map(i, 0, maxParts - 1, 0, 25);
  51.       var pos = this.history[i];
  52.       stroke(bg);
  53.       fill(this.baseCol + random(-50, 50), .9, .9);
  54.       ellipse(pos.x, pos.y, sz, sz);
  55.     }
  56.   }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement