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

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

CSS

              
                body {
  text-align: center;
}

div {
  display: inline-block;
  box-shadow: 0px 0px 10px rgba(black, .2);
  margin: 10px 0;
}
canvas{
  display: block;
}
              
            
!

JS

              
                // TO DO get this var by looping through number of photos
const imgnum = 5;

// find the canvas
const canvas = document.querySelector("#canvas")

//set stage
const app = new PIXI.Application({
  view: canvas,
  autoResize: true,
  resolution: devicePixelRatio, 
  transparent: true
});

//create container
const container = new PIXI.Container();
const displacementContainer = new PIXI.Container();
app.stage.addChild(container);
app.stage.addChild(displacementContainer);
const renderer = new PIXI.autoDetectRenderer();

//set filters resolution for device
PIXI.settings.FILTER_RESOLUTION = devicePixelRatio;

const columnGap = 20;

let gridimg;
// get our images pushed into an array
const gridimgs = [];
for (let i = 0; i < imgnum; i++){
  // get random images
  const baseimg = 'https://source.unsplash.com/random/600x600/?';
  
  //create sprite (using i to make image unique)
  gridimg = PIXI.Sprite.fromImage(baseimg + i);
  
  //image size settings
  gridimg.anchor.set(0); //position from top left
  gridimg.width = (300); //image size
  gridimg.height = (300); //image size
  
  // push to array for layout and animations
  gridimgs.push(gridimg)
  
}

//set up media query to control grid
const mq = window.matchMedia( "(max-width: 940px)" );

const setGridImgs = (cols) => { //cols is passed in per screen size
  let col = -1; // set initial col to -1 so that we can position first at 0;
  // app.resolution.set(devicePixelRatio);
  for (let i = 0; i < imgnum; i++){
    
    // add the images to container
    container.addChild(gridimgs[i]) 
     
    //create row index
    const rowMultiplier = Math.ceil((i + 1)/cols) - 1;

        
    let row = (rowMultiplier * 400) + (rowMultiplier * columnGap); // 400 is image height
    
    // columns index
    col++
    if (col > (cols - 1)) {
      col = 0
    } 
 
    
    const xPosition = ((app.renderer.width / devicePixelRatio + columnGap) / cols * (col))

    gridimgs[i].position.set(xPosition, row);
    
  }
}



//grid settings:

let cols = 3;//number of columns
setGridImgs(cols)
//media query code
const setCols = () => {
  if (mq.matches) {

    app.renderer.resize(620, 1200);
    cols = 2;
    setGridImgs(cols)
  }
  else {
    app.renderer.resize(940, 800);
    cols = 3;
    setGridImgs(cols)
  }
}
setCols(mq)
mq.addListener(setCols);





const ripples = [];
const filters = [];

//10 total ripples
for (let i = 0; i < 10; i++) {
  const texture = PIXI.Texture.fromImage('https://s3-us-west-2.amazonaws.com/s.cdpn.io/1600187/ripple.png')
  
  const ripple = new PIXI.Sprite(texture);
  
  ripple.anchor.set(0.5);
  
  ripple.scale.set(0);
  
  displacementContainer.addChild(ripple);
  // container.addChild(ripple);
  const filter = new PIXI.filters.DisplacementFilter(ripple)
  filter.scale.set(0)
  
  filters.push(filter)
  ripples.push(ripple)
  
}

container.filters = filters;

function MakeWaves(x, y, i) {
  
  ripples[i].position.set(x, y);
  runTweens(ripples[i], filters[i]);
}

runTweens = (ripple, filter) => {

  const tl = new TimelineMax()
  tl
    .set(filter.scale, { x: 0, y: 0 })
    .add('sync')
    .fromTo(ripple.scale, 1,{ x: .1, y: .1 }, { x: .74, y: .74 }, 'sync')
    .fromTo(filter.scale, 1, { x: 50, y: 50 },{ x: 0, y: 0 }, 'sync')
}


//TODO rework this per what animations are going to be... maybe move up to image setup

//animation settings 
for (let i = 0; i < imgnum; i++){
  
  //allow images to be interactive
  gridimgs[i].interactive = true;
  gridimgs[i].buttonMode = true;
  
  
  let index = -1;
  gridimgs[i].on('mouseover', function(ev) {
    var mousePositionX = app.renderer.plugins.interaction.mouse.global.x;
    var mousePositionY = app.renderer.plugins.interaction.mouse.global.y;

    index++
    if (index > 9) { //for the 10 total ripple sprites 
      index = 0;
    } 
    MakeWaves(mousePositionX, mousePositionY, index);
  }, false)  
}




// const loadSprite = PIXI.Sprite.fromImage('https://s3-us-west-2.amazonaws.com/s.cdpn.io/1600187/waterTemp.jpg');
// loadSprite.texture.baseTexture.wrapMode = PIXI.WRAP_MODES.REPEAT;
// loadSprite.scale.set(0);
// loadSprite.anchor.set(0);

// const loadFilter = new PIXI.filters.DisplacementFilter(loadSprite)
// loadFilter.scale.x = 0;
// loadFilter.scale.y = 0;

// container.filters = [loadFilter]


// TweenMax.from(container, 1, {
//   alpha: 0,
//   repeatDelay: 4, 
//   ease: Power3.easeOut,
//   yoyo: true, 
//   delay: 2,
// })


//see if this can be simplified
// TweenMax.from(loadSprite.anchor, 1, {
//   y: 0.35,
//   x: 0.25,
//   ease: Power1.easeOut,
//   repeatDelay: 4, 
//   yoyo: true, 
//   delay: 2,
// })
// TweenMax.from(loadFilter.scale, 1, {
//   x: 900, 
//   y: 9500, 
//   ease: Power1.easeOut,
//   delay: 2,
// })

              
            
!
999px

Console