Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var particles = [];
- var bg = "#202020";;
- function setup() {
- createCanvas(540, 540);
- colorMode(HSB, 360, 1, 1);
- }
- function draw() {
- background(bg);
- for (var i = 0; i < particles.length; i++) {
- particles[i].update();
- particles[i].paint();
- }
- }
- function mousePressed() {
- particles.push(new Particle(mouseX, mouseY));
- }
- function keyPressed() {
- saveFrames("anim/image-", "png", 5, 30);
- }
- function Particle(x, y) {
- this.x = x;
- this.y = y;
- this.history = [];
- this.baseCol = random(360);
- var maxParts = 25; //, n = frameCount;
- this.update = function() {
- var r = 10;
- this.x += random(-r, r);
- this.y += random(-r, r);
- /* var nx = map(noise((n+frameCount)/1),0,1,-r,r);
- var ny = map(noise((2*n+frameCount)/1),0,1,-r,r);
- this.x += nx;
- this.y += ny;
- */
- var v = createVector(this.x, this.y);
- this.history.push(v);
- if (this.history.length > maxParts) {
- this.history.splice(0, 1);
- }
- }
- this.paint = function() {
- for (var i = 0; i < this.history.length; i++) {
- var sz = map(i, 0, maxParts - 1, 0, 25);
- var pos = this.history[i];
- stroke(bg);
- fill(this.baseCol + random(-50, 50), .9, .9);
- ellipse(pos.x, pos.y, sz, sz);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement