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 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

              
                <canvas id="stage"></canvas>
              
            
!

CSS

              
                #stage {
  position: fixed;
  top: 0;
  left: 0;
  margin: 0;
}
              
            
!

JS

              
                console.clear();
var log = console.log.bind(console);

//
// POINT
// ===========================================================================
class Point {
  
  constructor(x = 0, y = 0) {
    this.x = x;
    this.y = y;
  }

  static fromBezier(bezier, t) {
    var a = bezier[0];
    var b = bezier[1];
    var c = bezier[2];
    var d = bezier[3];

    var ab = Point.lerp(a, b, t);
    var bc = Point.lerp(b, c, t);
    var cd = Point.lerp(c, d, t);

    ab.lerp(bc, t);
    bc.lerp(cd, t);

    return ab.lerp(bc, t);
  }

  static lerp(point1, point2, t) {
    var x = point1.x + (point2.x - point1.x) * t;
    var y = point1.y + (point2.y - point1.y) * t;
    return new Point(x, y);
  }

  lerp(point, t) {      
    this.x += (point.x - this.x) * t;
    this.y += (point.y - this.y) * t;
    return this;
  }
  
  copy(point) {
    return this.set(point.x, point.y);
  }
  
  set(x, y) {      
    this.x = x || 0;
    this.y = y || ((y !== 0) ? x : 0);
    return this;
  }
}

//
// GRID
// ===========================================================================
class Grid {
  
  constructor(rows, cols, width, height, vertices) {
    
    this.rows = rows;
    this.cols = cols;
    this.vertices = vertices;
    this.points = [];

    for (var y = 0; y < rows; y++) {
      
      var normY = y / (rows - 1);
      for (var x = 0; x < cols; x++) {
        
        var normX = x / (cols - 1);
        this.points.push(new Point(normX * width, normY * height));
      }
    }
    
    this.tl = this.points[0];
    this.tr = this.points[cols - 1];
    this.br = this.points[this.points.length - 1];
    this.bl = this.points[this.points.length - cols];

    this.cpL0 = new Point(0, height * 1 / 3);
    this.cpL1 = new Point(0, height * 2 / 3);
    this.cpR0 = new Point(width, height * 1 / 3);
    this.cpR1 = new Point(width, height * 2 / 3);
    this.cpT0 = new Point(width * 1 / 3, 0);
    this.cpT1 = new Point(width * 2 / 3, 0);
    this.cpB0 = new Point(width * 1 / 3, height);
    this.cpB1 = new Point(width * 2 / 3, height);
    
    this.bezierT = [this.tl, this.cpT0, this.cpT1, this.tr];
    this.bezierB = [this.bl, this.cpB0, this.cpB1, this.br];
    this.bezierL = [this.tl, this.cpL0, this.cpL1, this.bl];
    this.bezierR = [this.tr, this.cpR0, this.cpR1, this.br];
  }

  update() {
    
    var rows = this.rows;
    var cols = this.cols;
        
    for (var iy = 0; iy < rows; iy++) {

      var y = iy / (rows - 1);
      
      var yl = Point.fromBezier(this.bezierL, y);
      var yr = Point.fromBezier(this.bezierR, y);

      var cp0 = Point.lerp(this.cpT0, this.cpB0, y);
      var cp1 = Point.lerp(this.cpT1, this.cpB1, y);
      
      for (var ix = 0; ix < cols; ix++) {

        var i = ix + iy * cols;
        var q = this.points[i];
        var x = ix / (cols - 1);

        var k = Point.fromBezier([yl, cp0, cp1, yr], x);      
        q.copy(k);          
        
        var ii = i * 2;        
        this.vertices[ii] = k.x;
        this.vertices[ii+1] = k.y;
      }
    }    
  }
}

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

var vw = window.innerWidth;
var vh = window.innerHeight;

var app = new PIXI.Application(vw, vh, {
  resolution: window.devicePixelRatio || 1,
  view: document.getElementById("stage"),
  backgroundColor: 0xffffff,
  antialias: true,
  autoResize: true,
});

var loader = new PIXI.loaders.Loader(baseUrl)
  .add("beach", "beach7.jpg?v=" + Date.now())
  .load(init);

function init(loader, resources) {
  
  var rows = 40;
  var cols = rows;

  var texture = resources.beach.texture;
  var width = texture.width;
  var height = texture.height;

  var beach = new PIXI.mesh.Plane(texture, rows, cols);
  beach.position.set(vw / 2 - width / 2, vh / 2 - height / 2);

  app.stage.addChild(beach);

  var grid = new Grid(rows, cols, width, height, beach.vertices);
    
  var targets = [
    grid.tl,
    grid.cpT0,
    grid.cpT1,
    grid.tr,
    grid.cpR0,
    grid.cpR1,
    grid.br,
    grid.cpB1,
    grid.cpB0,
    grid.bl,
    grid.cpL1,
    grid.cpL0
  ];
  
  var shapeData = targets.map(target => ({ target, x: target.x, y: target.y }));
  
  var duration = 1.5;
  
  TweenLite.defaultEase = Elastic.easeOut;
  
  var twist1 = getTwist(0, 0, width, height, 1.5);
  var twist2 = getTwist(0, 0, width, height, -1.5);
  
  var tl = new TimelineMax({ 
    repeat: -1,
    onUpdate: grid.update, 
    callbackScope: grid
  });
  
  tl.add("twist1");
    
  targets.forEach((target, i) => {
    var ii = i * 2;
    tl.to(target, duration, { x: twist1[ii], y: twist1[ii+1] }, "twist1");
  });
  
  tl.add("twist2+=1");
    
  targets.forEach((target, i) => {
    var ii = i * 2;
    tl.to(target, duration, { x: twist2[ii], y: twist2[ii+1] }, "twist2");
  });
  
  tl.add("normalShape+=1");
    
  shapeData.forEach(shape => {
    tl.to(shape.target, duration, { x: shape.x, y: shape.y }, "normalShape");
  });
    
  window.addEventListener("resize", () => {
    vw = window.innerWidth;
    vh = window.innerHeight;
    app.renderer.resize(vw, vh);
    beach.position.set(vw / 2 - width / 2, vh / 2 - height / 2);
  });
}

function getTwist(x, y, w, h, strength = 1) {
  
  var _tl = {},
    _tr = {},
    _sin,
    _cos,
    _rotateDif = function(p, x, y) {
      p.x = x * _cos - y * _sin - x;
      p.y = y * _cos + x * _sin - y;
    },
    r = x + w,
    b = y + h,
    bow = strength * Math.max(h, w) * 0.1,
    top = -bow,
    right = bow,
    bottom = bow,
    left = -bow,
    topCornerPull = 0,
    cpx,
    cpy;

  cpx = w / 4; //controls how far the control points are from the corners (4 would mean they're 1/4 into the line).
  cpy = h / 4;
  _cos = Math.PI * 0.05 * strength;
  _sin = Math.sin(_cos);
  _cos = Math.cos(_cos);
  _rotateDif(_tl, -w / 2, -h / 2);
  _rotateDif(_tr, w / 2, -h / 2); //note: bottom right is just the inverse of top left values, and bottom left is inverse of top right.

  return [
    x + _tl.x, y + _tl.y,
    x + cpx - _tl.x, y - _tl.y,
    r - cpx - _tr.x, y - _tr.y,
    r + _tr.x, y + _tr.y,
    r + _tr.x, y + cpy + _tr.y,
    r - _tl.x, b - cpy - _tl.y,
    r - _tl.x, b - _tl.y,
    r - cpx + _tl.x, b + _tl.y,
    x + cpx + _tr.x, b + _tr.y,
    x - _tr.x, b - _tr.y,
    x - _tr.x, b - cpy - _tr.y,
    x + _tl.x, y + cpy + _tl.y,
    x + _tl.x, y + _tl.y
  ];
}

              
            
!
999px

Console