css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <p id="loading">Loading...</p>
<main>  
  <svg id="svg" viewBox="0 0 1200 870" preserveAspectRatio="xMinYMin meet" style="enable-background:new 0 0 1200 870;">    
    <defs>
      <path id="path" d="M 331 162 C 359.8 129.7 399.1 107.2 441.3 97.6 C 483.5 88.1 528.4 91.5 569 106.5 C 609.6 121.4 645.8 147.8 673.1 181.4 C 700.5 214.9 719 255.4 727.4 297.8 C 744.2 382.7 719.1 473.6 666.4 542.2 C 613.7 610.8 535.1 657.6 451 678 C 408.1 688.4 363.4 692.3 319.6 687.1 C 275.7 681.9 232.7 667.4 196 643 C 159.2 618.6 128.8 584.1 111.3 543.5 C 93.8 503 89.7 456.4 102 414 C 110.9 383.3 128.2 355.1 151.5 333.2 C 174.7 311.3 203.8 295.6 234.8 288.1 C 265.9 280.7 298.9 281.3 329.6 289.9 C 360.4 298.4 389 314.8 412 337 C 449.9 373.5 472.2 426.5 468.6 479 C 466.8 505.3 458.7 531.1 444.8 553.5 C 430.9 575.8 411.2 594.6 388 607 C 355.9 624.2 317.5 628.9 282 621 C 254.9 615 229.2 601.7 209.7 581.9 C 190.2 562.1 177.2 535.7 175 508 C 173.5 488.9 177 469.6 184.7 452.1 C 192.3 434.6 204.1 418.9 218.4 406.3 C 247.2 381.1 285.8 368.5 324 368 C 365.7 367.4 406.7 380.5 443.5 400.1 C 480.3 419.7 513.3 445.7 545.2 472.6 C 577.1 499.4 608.2 527.4 642.2 551.5 C 676.2 575.6 713.5 596 754 606 C 801.2 617.6 851.9 614.4 897.6 597.6 C 943.2 580.8 983.7 550.5 1013.2 511.8 C 1042.8 473.2 1061.4 426.3 1067 378 C 1072.7 329.7 1065.5 280 1047 235 C 1026.5 185.1 992 140.9 947.8 110 C 903.7 79 849.9 61.6 796 62 C 753.9 62.3 711.8 73.5 675.8 95.1 C 639.7 116.7 609.8 148.9 592 187 C 572.6 228.5 567.9 276.6 577.8 321.4 C 587.6 366.1 611.7 407.5 645 439 C 674.9 467.2 711.4 487.4 748.3 505.3 C 785.3 523.3 823.3 539.4 858.3 561 C 893.2 582.7 925.4 610.4 945.4 646.4 C 955.3 664.4 962.1 684.2 964.1 704.7 C 966.1 725.1 963.2 746.2 955 765 C 947.2 782.8 934.7 798.4 919.6 810.6 C 904.5 822.8 886.9 831.8 868.4 837.8 C 831.5 849.7 791.7 849.8 753 846 C 648.1 835.7 545.9 796.8 462 733 C 398.4 684.6 345.4 621.9 310.9 549.9 C 276.5 477.8 260.8 396.5 269 317 C 274.8 260.7 293.3 204.2 331 162" />
    </defs>    
  </svg>
  <canvas id="view"></canvas>
</main>
            
          
!
            
              html, body {
  height: 100%;
}

body {
  overflow: hidden;
  background: black;
  color: #aaa;
}

main {
  position: relative;
  visibility: hidden;
  transform-origin: left top;
  height: 100%;
  width: 100%;
}

svg, canvas {
  position: absolute;
  width: 100%;
  height: 100%;
  max-height: 870px;
}

path {
  fill: none;
  stroke: #555;
  stroke-width: 2;
}

#loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

            
          
!
            
              console.clear();

// var baseURL = "http://crossorigin.me/https://s3-us-west-2.amazonaws.com/s.cdpn.io/106114/";
var baseURL = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/106114/";

var w = window.innerWidth;
var h = window.innerHeight;

var perf = window.performance;
var now  = perf ? perf.now.bind(perf) : Date.now;

var linear = Linear.easeNone;

var loader = new PIXI.loaders.Loader(baseURL)
  .add("fighter-02.json?v=4")
  .add("trail", "particle01.png?v=4")  
  .load((loader, assets) => new Demo(assets))

//
// DEMO
// ===========================================================================
class Demo {

  constructor(assets) {

    _.bindAll(this);

    this.last = now();
    this.time = 0;    
    this.size = { x: 1200, y: 870 };

    this.renderer = PIXI.autoDetectRenderer(this.size.x, this.size.y, {
      view: document.querySelector("#view"),
      backgroundColor: 0x0A0A0A
    });

    this.stage   = new PIXI.Container();
    this.fighter = new Fighter(this.stage, assets);
    
    window.addEventListener("resize", this.resize);

    TweenLite.ticker.addEventListener("tick", this.render);

    this.resize();

    TweenLite.set("#loading", { autoAlpha: 0 });
    TweenLite.to("main", 0.5, { autoAlpha: 1 });
  }

  render() {

    var current = now();
    this.time = current - this.last;
    this.last = current;
    this.fighter.update(this.time);
    this.renderer.render(this.stage);
  }

  resize() {

    w = window.innerWidth;
    h = window.innerHeight;

    var ratio = Math.min(w / this.size.x, h / this.size.y);

    this.stage.scale.set(ratio); 
    this.renderer.resize(w, h);
  }
}

//
// MOTION PATH
// ===========================================================================
class MotionPath {

  constructor(path) {

    this.values = MorphSVGPlugin.pathDataToBezier(path);    
    
    this.lines  = [];
    this.speeds = [];
    this.steps  = 1000;
    
    this.speed = {
      now   : 1,
      min   : 0.5,
      max   : 2.5,
      ratio : 0.5,
      step  : 0.015
    };

    this.bezier = {
      autoRotate : ["x", "y", "rotation", Math.PI / 2, true],
      values     : this.values,
      type       : "cubic"          
    };

    this.init();
  }

  init() {

    var speed = this.speed;
    var lines = this.lines;

    var obj = { x: 0, y: 0, rotation: 0 };

    var tween = TweenLite.to(obj, 1, {
      bezier : { values: this.values, autoRotate: true, type: "cubic" },
      paused : true, 
      ease   : linear
    });
    
    // Loop through it twice to blend the start and end speeds together
    for (var loops = 0; loops < 2; loops++) {      
      for (var i = 0; i <= this.steps; i++) {

        tween.progress(i * 0.001);

        var rot  = obj.rotation % 90;
        var sign = rot < 0 ? -1 : 1;
        var mult = Math.abs(rot / 90);
        var diff = (speed.ratio + speed.step * sign * mult) || 0;

        speed.ratio = clamp(diff, 0, 1);

        if (!loops) continue;
        
        var color = lerpColor(speed.ratio);

        lines.push({ color, x: obj.x, y: obj.y });

        speed.now = lerp(speed.min, speed.max, speed.ratio);

        this.speeds.push(speed.now);
      } 

      speed.now = lerp(speed.min, speed.max, speed.ratio);
    }    

    this.plotSpeed();
  }

  plotSpeed() {
    
    var graphics = new PIXI.Graphics();
    
    var size = this.lines.length;  
    var prev = this.values[0];   

    for (var i = 0; i < size; i++) {

      var line = this.lines[i];

      graphics.beginFill(line.color);
      graphics.lineStyle(4, line.color);
      graphics.drawPolygon(prev.x, prev.y, line.x, line.y, prev.x, prev.y);      
      graphics.endFill();

      prev = line;
    } 

    var box = graphics.getBounds();

    graphics.lineStyle(0);
    graphics.beginFill(0x000000, 0);
    graphics.drawRect(0, 0, box.x + box.width, box.y + box.height);

    this.texture = graphics.generateTexture();
    this.sprite  = new PIXI.Sprite(this.texture);

    graphics.destroy();
  }
}

//
// FIGHTER
// ===========================================================================
class Fighter {

  constructor(parent, assets) {

    this.stallSpeed = 0.55;

    this.sprite = new FighterSprite();

    this.spriteContainer  = new PIXI.Container();
    this.emitterContainer = new PIXI.Container();

    this.emitter    = new Emitter(this.emitterContainer, assets.trail.texture);    
    this.motionPath = new MotionPath("#path");

    this.speeds = this.motionPath.speeds;
    
    _.bindAll(this);

    this.bezierTween = TweenLite.to(this.spriteContainer, 5, {
      bezier : this.motionPath.bezier,
      paused : true, 
      ease   : linear
    });

    this.progressTween = TweenMax.to(this.bezierTween, 5, {
      progress :  1,
      repeat   : -1,
      ease     : linear,
      onStart  : this.setSpeed,
      onUpdate : this.setSpeed      
    });

    this.spriteContainer.addChild(this.sprite);

    parent.addChild(this.motionPath.sprite);
    parent.addChild(this.emitterContainer);
    parent.addChild(this.spriteContainer);
    
    this.emitter.emit = true;
  }

  get x() { return this.spriteContainer.x; }
  get y() { return this.spriteContainer.y; }

  setSpeed() {

    var index = Math.round(this.progressTween.progress() * 1000);
    var speed = this.speeds[index];

    TweenLite.to(this.progressTween, 0.2, { timeScale: speed });
    
    if (speed < this.stallSpeed && !this.sprite.inRoll) {
      this.sprite.roll();
    }
  }

  update(time) {
    this.emitter.spawn(this.x, this.y, time * 0.001);
  }
}

//
// FIGHTER SPRITE
// ===========================================================================
class FighterSprite extends PIXI.Sprite {

  constructor() {
    super();

    this.total  = 30;
    this.frames = new Array(this.total);
    
    for (var i = 0; i < this.total; i++) {
      var frame = `rollSequence00${i < 10 ? "0" + i : i}.png`;
      this.frames[i] = PIXI.Texture.fromFrame(frame);
    }

    this.anchor.set(0.5, 0.6);
    this.pivot.set(0.5);  
    
    this.frame  = 0;
    this.inRoll = false;
  }

  get frame() { return this._frame; }
  set frame(n) {
    n = n % this.total;
    this._frame  = n;
    this.texture = this.frames[n];
  }

  roll() {

    this.inRoll = true;

    TweenLite.to(this, 1, {
      frame: this.total,
      ease : linear,
      roundProps: "frame",      
      onComplete: () => { this.inRoll = false; }
    });
  }
}

//
// EMITTER
// ===========================================================================
class Emitter {

  constructor(container, texture) {

    this.container = container;

    this.emitter = new cloudkid.Emitter(this.container, [texture], {
      alpha: { start: 0.8, end: 0.1 },
      scale: { start: 1, end: 0.3, minimumScaleMultiplier: 1 },
      color: { start: "#e3f9ff", end: "#0ec8f8" },
      speed: { start: 0, end: 0 },
      acceleration : { x: 0, y: 0 },
      startRotation: { min: 0, max: 0 },
      rotationSpeed: { min: 0, max: 0 },
      lifetime : { min: 0.4, max: 0.4 },
      blendMode: "normal",
      frequency: 0.008,
      emitterLifetime: -1,
      maxParticles: 1000,
      pos: { x: 0, y: 0 },
      addAtBack: false,
      spawnType: "point"
    });
  }

  set emit(flag) { this.emitter.emit = flag; }

  spawn(x, y, time) {
    this.emitter.updateSpawnPos(x, y);
    this.emitter.update(time);
  }  
}

//
// LERP COLOR
// ===========================================================================
function lerpColor(progress = 0) {

  var color1 = [255, 0, 0];
  var color2 = [0, 255, 0];
  var rgb = [];

  for (var i = 0; i < 3; i++) {

    var rgb1 = Math.pow(color1[i], 2);
    var rgb2 = Math.pow(color2[i], 2);

    rgb[i] = Math.round(Math.sqrt(lerp(rgb1, rgb2, progress)));
  } 

  return ((1 << 24) + (rgb[0] << 16) + (rgb[1] << 8) + rgb[2]);
}

//
// LERP
// ===========================================================================
function lerp(start, stop, amt) {
  amt = clamp(amt, 0, 1);
  return start + (stop - start) * amt;
}

//
// CLAMP
// ===========================================================================
function clamp(value, a, b) {
  return value < a ? a : (value > b ? b : value);
}


            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console