cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <canvas id="test" width="500" height="500"></canvas>
	<a href="https://createjs.com/" target="_blank"><img id="logo" src="https://createjs.com/mediakit/createjs-badge-reverse.png"></a>

	<img id="badge" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1524180/Button_Follow_White.svg">
	<img id="badge2" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1524180/Button_Hold_White.svg">
            
          
!
            
              html, body {
  background-color: #4ACFF1;
  padding:0px;
  margin: 0px;
  overflow: hidden;
}
#logo {
  position: absolute;
  right:0px;
  bottom:0px;
}

#badge {
  width:60px;
  height:70px;
  position: absolute;
  left:10px;
  bottom:10px;
}
#badge2 {
  width:60px;
  height:70px;
  position: absolute;
  left:70px;
  bottom:10px;
}

canvas {
  position: absolute;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}
            
          
!
            
              var boxes = [];
var image;
var total = 1500;
var isDown = false;
var multipler = 0;
var titleImg;
var q = null;
var isReady = false;

function init() {
  var manifest = [
    {id:"title",src:"https://s3-us-west-2.amazonaws.com/s.cdpn.io/1524180/Title.png"},
    {id:"oreo",src:"https://s3-us-west-2.amazonaws.com/s.cdpn.io/1524180/Oreo.png"},
  ]
  q = new createjs.LoadQueue(true);
  q.on("complete", assetLoaded);
  q.loadManifest(manifest);
}

function assetLoaded() {
  canvas = document.getElementById("test");

  stage = new createjs.StageGL(canvas);
  stage.addEventListener("stagemousedown", handleDown);
  stage.addEventListener("stagemouseup", handleUp);
  stage.setClearColor("#4ACFF1");

  createjs.Touch.enable(stage);

  window.addEventListener('resize', onResize);

  title = new createjs.Bitmap(q.getResult('title'));
  stage.addChild(title);
  stage.update();

  onResize();
  buildCookies();
  setTimeout(function () {
    isReady = true;
  }, 1000)

}

function handleDown() {
  isDown = true;
}

function handleUp() {
  isDown = false;

  multipler = 0;
}

function updatePower() {
  if (isDown) {
    multipler =  Math.min(1, multipler+0.03);
  }
}

function buildCookies() {
  var bit;
  for(var i=0;i<total;i++) {
    bit = new createjs.Bitmap(q.getResult('oreo'));
    bit.x = Rnd(-100,canvas.width);
    bit.scale= .1+Math.random()*.5;
    bit.y = Rnd(-1500, -300);
    bit.speedY = Rnd(4, 10);
    boxes.push(bit);
    stage.addChild(bit);
  }

  createjs.Ticker.timingMode = createjs.Ticker.RAF;
  createjs.Ticker.on("tick", tick);

}

function onResize(event) {
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;

  var scale = Math.min(this.stage.canvas.width, this.stage.canvas.height)/720;

  title.scale = Math.min(1,scale);
  title.x = canvas.width - (title.image.width*title.scale) >> 1;
  title.y = canvas.height - (title.image.height*title.scale) >> 1;



  stage.updateViewport(canvas.width, canvas.height);
}

function avoid(event) {
  maxStrength = 750*multipler;
  var l = boxes.length;
  for(var i=0;i<l;i++) {
    var box = boxes[i];
    var dx = box.x - stage.mouseX;
    var dy = box.y - stage.mouseY;
    var angle = Math.atan2(dy, dx);
    var dis = Math.sqrt(dx*dx+dy*dy);
    var f = maxStrength / dis*2;
    box.x += Math.cos(angle) * f;
    box.y += Math.sin(angle) * f *2;
  }
}

function move() {
  var l = boxes.length;
  for(var i=0;i<l;i++) {
    var box = boxes[i];
    box.y += box.speedY;
    if (box.y > canvas.height) {
      box.x = Rnd(-100,canvas.width)
      box.y = Rnd(-200, -100);
      box.speedY = Rnd(4, 10);
    }
  }
}

function tick(event) {
  if (isReady === true) {
    updatePower();
    avoid();
    move();
  }

  stage.update(event);
}
init();
            
          
!
999px
Loading ..................

Console