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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                
              
            
!

JS

              
                console.clear();

var baseUrl = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/106114/";

var app = new PIXI.Application(900, 500, {
  resolution: window.devicePixelRatio || 1,
  backgroundColor: 0x000000,
  antialias: true,
  autoResize: true
});

document.body.appendChild(app.view);

var waves = [];
var waveIndex = 0;

var loader = new PIXI.loaders.Loader(baseUrl)
  .add("particle", "particle-01.png?v=1")
  .load(init);

function init(loader, resources) {
  
  var texture = resources.particle.texture;
  
  for (var i = 0; i < 15; i++) {
    
    var wave = createParticleWave(texture, 1000);
    app.stage.addChild(wave.container);
    waves.push(wave);
  }
  
  app.view.addEventListener("mouseenter", playWave);
}

function createParticleWave(texture, numParticles) {
    
  var container = new PIXI.Container();  
  container.visible = false;
  
  var particleContainer = new PIXI.ParticleContainer(numParticles, {
    scale: true,
    position: true,
    rotation: false,
    uvs: false,
    alpha: true
  });
  
  container.addChild(particleContainer);
  
  var tl = new TimelineMax({
    paused: true,
    onStart: function() {
      container.visible = true;
    },
    onComplete: function() {
      container.visible = false;
    }
  });
  
  var particles = [];
  
  for (var i = 0; i < numParticles; i++) {
    
    var particle = new PIXI.Sprite(texture);
       
    // anchor and pivot are like transform origin
    // .set() with 1 parameter applies value to x and y property
    // particle.anchor.set(0.5) is the same as
    // particle.anchor.set(0.5, 0.5) or
    // particle.anchor.x = 0.5;
    // particle.anchor.y = 0.5;
    particle.anchor.set(0.5);
    particle.pivot.set(0.5);
    
    particle.alpha = 0;
    
    // Could also use .set() here with position
    // particle.position.set(random(900), random(200, 500))
    particle.x = random(900);
    particle.y = random(200, 500);
    
    // The particle texture is 44x44
    // Changing the width and height will change the scale
    var size = random(1, 6);
    particle.width = size;
    particle.height = size;
    
    //console.log("Scale X", particle.scale.x);
        
    var duration = 6;
    var delay = random(1);
    var velocity = random(25, 125);
    var angle = random(-100, -10);
    var gravity = 20;
    var endSize = random(size * 0.5, size * 1.75);
    
    
    tl.to(particle, 0.2, { alpha: 1 }, delay)
      .to(particle, 0.5, { alpha: 0 }, delay + duration - 0.5)
      .to(particle, duration, {
        width: endSize,
        height: endSize,
        physics2D: {
          velocity: velocity,
          angle: angle,
          gravity: gravity
        }
      }, delay);
        
    particles.push(particle);
    particleContainer.addChild(particle);
  }
    
  return {
    container: container,
    particles: particles,
    timeline: tl
  };
}

function playWave() {
  
  var wave = waves[waveIndex % waves.length];
    
  if (!wave.timeline.isActive()) {
    wave.timeline.restart();
  } 
  
  waveIndex++;
}

function random(min, max) {
  if (max == null) { max = min; min = 0; }
  return Math.random() * (max - min) + min;
}
              
            
!
999px

Console