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

HTML

              
                <div id="tpCanvas"></div>
<div class="message">
  <h1>Click to add toilet paper to your cart</h1>
  <p> It should be so simple, right? But it vanishes in a puff of smoke. Was it real or did you imagine it? You're in the TP Wasteland. Stay safe CodePen community.</p>
</div>

<div id="cart"></div>
<img class="avatar" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/314556/demoAvatar" alt="Craigs avatar">
<a class="twitterLink" target="_blank" href="https://twitter.com/Craig_PointC">Follow me on Twitter</a>

              
            
!

CSS

              
                body {
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background: #333;
  font-family: "proxima-nova", sans-serif;
  background: radial-gradient(
    circle at center center,
    rgb(40, 40, 70),
    rgb(10, 10, 5)
  );
}
h1,
p {
  line-height: 1.3;
  margin: 8px 0;
}
h1 {
  color: #42a6e0;
}
#tpCanvas {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  /*   background: green; */
  z-index: 5;
}
.message {
  color: white;
  padding: 10px;

  /* background: black; */
  max-width: 640px;
  margin: auto;
}

#cart {
  width: 115px;
  height: 150px;
  position: absolute;
  bottom: 0;
  right: 20px;
  z-index: 2;
  background: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/314556/shoppingCart.svg")
    center bottom no-repeat;
  opacity: 0.8;
  background-size: contain;
}

.avatar {
  position: absolute;
  bottom: 0;
  left: 80px;
  display: block;
  width: 120px;
  height: auto;
  z-index: 2;
}

.twitterLink {
  position: absolute;
  text-decoration: none;
  font-size: 0.7rem;
  color: white;
  background: #42a6e0;
  padding: 4px 12px;
  border-radius: 4px;
  bottom: 30px;
  left: 10px;
  z-index: 20;
}

              
            
!

JS

              
                console.clear();
PIXI.utils.skipHello();
let iw = window.innerWidth;
let ih = window.innerHeight;
let count = 24;
let smoke;
let tpTexture;
let packageOfPaper = [];
const canvas = document.querySelector("#tpCanvas");

//create PIXI app
const app = new PIXI.Application({
  resizeTo: canvas,
  antialias: true,
  autoDensity: true,
  transparent: true
});
canvas.appendChild(app.view);

//load assets
const loader = PIXI.Loader.shared;
loader.baseUrl = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/314556/";
loader.add("boomSheet", "kaboom.json").add("tpRoll", "toiletPaper.png");

loader.load((loader, resources) => {
  smoke = resources.boomSheet.spritesheet;
  tpTexture = resources.tpRoll.texture;
  for (let i = 0; i < count; i++) {
    makeRoll();
  }
});

//makes each roll and randomizes the size and color
function makeRoll() {
  let roll = new PIXI.Sprite.from(tpTexture);
  roll.tint = "random([#ffffff, #e1f7d5, #ffdfd3, #E0BBE4, #AEC6CF, #FDFD96, #AFEEEE, #dea5a4])";
  gsap.set(roll, {
    x: gsap.utils.random(0, iw),
    y: gsap.utils.random(0, ih),
    pixi: {
      anchor: 0.5,
      scale: gsap.utils.random(0.1, 0.25),
      tint: roll.tint
    }
  });
  roll.interactive = true;
  roll.buttonMode = true;
  roll.on("pointerdown", spareASquare);
  app.stage.addChild(roll);
  packageOfPaper.push(roll);
  wiggle(roll);
}

// explode the TP, remove it from the array and then make a new roll
function spareASquare(e) {
  let boom = new PIXI.AnimatedSprite(smoke.animations["boom"]);
  boom.onComplete = () => {
    boom.destroy();
  };
  gsap.set(boom, {
    x: this.x,
    y: this.y,
    loop: false,
    animationSpeed: 0.5,
    pixi: {
      colorize: this.tint,
      scale: gsap.utils.random(0.4, 0.8),
      anchor: 0.5,
      rotation: gsap.utils.random(0, 360)
    }
  });

  app.stage.addChild(boom);
  boom.play();
  let k = packageOfPaper.indexOf(this);
  packageOfPaper.splice(k, 1);
  gsap.killTweensOf(this);
  this.destroy();
  makeRoll();
}

// TP has to wiggle because what's life without a little wiggle?
function wiggle(target) {
  let rot = gsap.utils.random(0, 360);
  let dur = gsap.utils.random(45, 80);
  let xWiggle = gsap.utils.random(30, 80);
  let yWiggle = gsap.utils.random(30, 80);
  let wigs = gsap.utils.random(10, 20);
  gsap.to(target, {
    duration: dur,
    x: "+=" + xWiggle,
    repeat: -1,
    ease: CustomWiggle.create("", { type: "random", wiggles: wigs })
  });
  gsap.to(target, {
    duration: dur,
    y: "+=" + yWiggle,
    repeat: -1,
    ease: CustomWiggle.create("", { type: "random", wiggles: wigs })
  });
  gsap.to(target, {
    duration: dur,
    repeat: -1,
    ease: CustomWiggle.create("", { type: "random", wiggles: wigs }),
    pixi: { rotation: "+=" + rot }
  });
}

// kill the wiggle tweens, destroy the rolls, empty the array and make new rolls at the new stage size
function resizeStage() {
  for (let i = 0; i < packageOfPaper.length; i++) {
    let t = packageOfPaper[i];
    gsap.killTweensOf(t);
    t.destroy();
  }
  packageOfPaper = [];
  iw = window.innerWidth;
  ih = window.innerHeight;
  for (let i = 0; i < count; i++) {
    makeRoll();
  }
}
//throttle the resize event
let resize = gsap.delayedCall(0.25, resizeStage).pause();
window.addEventListener("resize", function() {
  resize.restart(true);
});

              
            
!
999px

Console