Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                body {
  overflow: hidden;
  margin: 0;
  padding: 0;
}

              
            
!

JS

              
                var fireworks = [];
var gravity;
var mic; 

var angle = 0;
//setting up the canvas
function setup() {
  createCanvas(windowWidth, windowHeight);
    gravity = createVector(0, 0.2);
  stroke(255);
  strokeWeight(4);
    background(0);
    mic = new p5.AudioIn();
    mic.start();
}

//Using sound to create an action
function draw() {
  background(0, 10);
    var vol = mic.getLevel();
    //creating a Min and a Max. 
    if(fireworks.length < 5 && vol > .01){
        var maxVol = round(vol * 100);
        if (maxVol > 12){
            maxVol = 12
        }
       for (var i = 0; i < maxVol; i++) {
        fireworks.push(new Firework());
    }
    }
    
    
    for (var i = fireworks.length - 1; i >= 0; i--) {
        fireworks[i].update();
        fireworks[i].show();
        if (fireworks[i].done()) {
            fireworks.splice(i, 1);
        }
    }
  
}

function mouseClicked() {
    for (var i = 0; i < random(1, 10); i++) {
            fireworks.push(new Firework());
        }
    
}

function Firework() {
    //colours of particle 
    this.hu = random(255);
    this.colorList = ['255, 120, 120', '156, 0, 255', '103, 17, 184', '94, 249, 152', '144,3,253', '7, 14, 104', '55,245, 220', '255, 255, 255', '137, 11, 29'];
    this.fcolor = random(this.colorList)
    this.firework = new Particle(random(width), height, this.fcolor, true);
    this.exploded = false;
    this.particles = [];
    
    
    this.done = function() {
        if (this.exploded && this.particles. length == 0){
            return true;
    } else { 
        return false;
    }
    }
    //Applying movemment 
    this.update = function() {
        if (!this.exploded) {
        this.firework.applyForce(gravity);
        this.firework.update(); 
              if (this.firework.vel.y >= 0) {
            this.exploded = true;
                  this.explode();
              }
        }

       for (var i = this.particles.length-1; i >=0; i--) {
        this.particles[i].applyForce(gravity); 
        this.particles [i].update();
           if (this.particles[i].done()) {
               this.particles.splice(i, 1);
           }
       }
    }
    //Amount of particles in explosion
    this.explode = function() {
        var exp = random(20, 500)
        for (var i = 0; i < exp; i++) {
            var p = new Particle(this.firework.pos.x, this.firework.pos.y, this.fcolor, false)
            this.particles.push(p);
        }
    }

    
    this.show = function() {
        if (!this.exploded) {
            this.firework.show();
    }
    for (var i = 0; i < this.particles.length; i++) {
        this.particles[i].show();
    }
    }

}

function Particle(x, y, hu, firework) {
    this.pos = createVector(random(x, x -100), random (y, y -100));
    this.firework = firework;
    this.lifespan = 400;
    this.hu = hu;
   
    if (this.firework) {
    this.vel = createVector(0, random(-20, -8));
    } else {
        this.vel = p5.Vector.random2D();
        this.vel.mult(random (2, 10));
    }
    this.acc = createVector(0, 0);

    this.applyForce = function(force) {
      this.acc.add(force);
    }

    this.update = function() {
        if (!this.firework) {
            this.vel.mult(0.9);
            this.lifespan -= 4;
        }
      this.vel.add(this.acc);
      this.pos.add(this.vel);
      this.acc.mult(0)
           
    }
    this.done = function() {
        if (this.lifespan <0) {
            return true;
        } else{
            return false;
        }
        }
    
//colouring and stroke weight of fireworks
    this.show = function() {
        if (!this.firework) {
        strokeWeight (2.5)
            stroke('rgba('+ this.hu + ',' + this.lifespan + ')');
        } else {
            strokeWeight(4);
            //stroke(this.hu, 255, 255);
            stroke('rgba('+ this.hu + ',' + this.lifespan + ')');
        }
            point(this.pos.x, this.pos.y);
    }

}
              
            
!
999px

Console