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.

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>
	<canvas id="canvas" width="550" height="500"></canvas>
</div>
<a href="https://createjs.com/" target="_blank"><img class="logo white verbose"></a>

<div id="badges">
  <div class="badge white move"></div>
  <div class="badge white click"></div>
</div>
            
          
!

CSS

            
              


            
          
!

JS

            
              var canvas = document.getElementById("canvas"),
  stage = new createjs.StageGL(canvas, {antialias:true});
stage.setClearColor("#000");
createjs.Ticker.timingMode = createjs.Ticker.RAF;
createjs.Touch.enable(stage);
var cont = stage.addChild(new createjs.Container())
  .set({mouseEnabled:false, mouseChildren:false});

// Load the banana
var img = document.createElement("img");
img.crossOrigin = "Anonymous";
img.src = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/1524180/Banana.png";
img.onload = init;
var bmp = new createjs.Bitmap(img);
handleResize();

var MAX_BANANAS = 3000;

var bananas = [];
function init() {
  createjs.Ticker.on("tick", tick);
  for (var i=0; i<100; i++) { tick(); }
}

// Tick Code
var clicked = false;
function tick(event) {
  addBanana();
  
  var factor = 1,
      DIST = canvas.width/10,
      ADD = 10;
  if (clicked) {
    factor = 5;
    DIST = canvas.width/5;
  }
  
  for (var i=bananas.length-1; i>=0; i--) {
    var b = bananas[i];
    b.y += b.speed;
    b.rotation = (b.rotation + b.rotationSpeed) % 360;
    b.speed *= 1.01;
    
    b.x += b.addX; // Add burst speed
    b.y += b.addY;
    b.addX *= 0.9; // Slow down the burst speed
    if (b.addY < 0) { b.addY *= 0.9; }
    
    var difX = stage.mouseX-b.x,
        difY = stage.mouseY-b.y,
        dist = Math.sqrt(difX*difX + difY*difY);
    if (Math.abs(dist) < DIST) {
      if (clicked) { b.rotationSpeed *= -difX/DIST * 10; }
      b.addX = -difX/DIST * ADD* (b.scale) * factor;
      b.addY = -difY/DIST * ADD* (b.scale) * factor;
    }
    
    if (b.y > canvas.height+30) {
      addBanana(b, i); // Reset banana
    }
  }
  clicked = false;
  stage.update(event);
}

function addBanana(b) {
  if (b) {
    // Nothing, its banana reuse
  } else if (bananas.length > MAX_BANANAS){
    return; // Too many bananas
  } else {
    // Make a new banana
    b = new createjs.Bitmap(img).set({
      regX: img.naturalWidth/2,
      regY: img.naturalHeight/2
    });
    bananas.push(b);
    cont.addChild(b);
  }
  
  // Reset banana props
  b.set({
    x:Math.random() * canvas.width,
    y: -30,
    speed: Math.random() * 6 + 1.5,
    rotation: Math.random() * 360,
    rotationSpeed: Math.random() * 3 - 1.5,
    addX: 0,
    addY: 0,
    power: 0
  });
  b.scale = b.speed/7.5; // Speed is a factor of scale
}

// Resize Code
window.addEventListener("resize", handleResize, false);
function handleResize(event) {
  var w = window.innerWidth,
      h = window.innerHeight;
  canvas.width = w; canvas.height = h;
  stage.updateViewport(w,h);
  // Layout other assets
  stage.update();
}

stage.on("stagemousedown", function() { clicked = true; })

createLockup(["EaselJS"]);
            
          
!
999px

Console