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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

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.

            
              <!--Depending on your screen size you may have to scroll ;)-->
<canvas></canvas>
<input type="button" onClick="change_color()" value="Add Color">

            
          
!
            
              body{
  margin: 0;
  padding: 0;
  background: #212121;
}

input[type="button"]{
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 10;
  width: 200px;
  height: 50px;
  background: #1F80D1;
  border-radius: 3px;
  font-family: Arial;
  font-size: 15px;
  color: #fff;
  cursor: pointer;
  border: 0px solid #fff;
  text-shadow: 0 1px 0 #0055A1;
}

input[type="button"]:hover{
  background: #0066B7;
}

input[type="button"]:focus{
  outline: none;
}
            
          
!
            
              //Forked by https://codepen.io/motorlatitude/pen/jLAhf
window.requestAnimFrame = (function(){
  return  window.requestAnimationFrame || 
    window.webkitRequestAnimationFrame || 
    window.mozRequestAnimationFrame    || 
    window.oRequestAnimationFrame      || 
    window.msRequestAnimationFrame     ||  
    function( callback ){
    window.setTimeout(callback, 1000 / 60);
  };
})();
/*Define Global Variabls */
var canvas = document.getElementsByTagName("canvas")[0];
var ctx = canvas.getContext("2d");
var w = 1500, h = window.outerHeight;
canvas.width = w;
canvas.height = h;
var counter = 0;
var counter2 = 0;
var add_color = false;

var particles = [];
//For those interested in how the array below generates the letters: [number of particles, min x coord, max x coord, min y coord, max y coord];
var c = [10,130,220,100,120, //C
         10,110,170,125,140,
         8,100,140,145,160,
         8,100,140,165,180,
         8,100,140,185,200,
         8,100,140,215,230,
         8,120,180,235,250,
         10,130,225,255,270,
         15,300,370,100,120, //O
         10,280,300,125,150,
         10,370,430,125,140,
         10,260,280,145,150,
         10,390,450,145,150,
         10,250,260,165,200,
         10,400,440,165,200,
         10,260,280,185,230,
         10,390,450,185,230,
         10,280,300,205,250,
         10,370,430,205,250,
         15,300,370,225,270,
         60,500,530,100,270, //D
         15,530,600,100,120,
         10,600,620,110,120,
         10,600,640,130,180,
         10,630,650,160,200,
         10,630,650,190,230,
         10,630,650,230,250,
         15,530,600,240,270,
         60,700,720,100,270, //E
         20,710,820,100,130,
         20,710,790,170,190,
         20,710,820,250,270,
         60,880,900,100,270, //P
         10,895,990,100,120,
         20,990,1000,110,190,
         10,895,1000,185,210,
         60,1080,1100,100,270, //E
         20,1090,1200,100,130,
         20,1090,1180,170,190,
         20,1090,1200,250,270,
         25,1280,1300,100,270, //N
         25,1380,1400,100,270,
         2,1295,1310,100,120,
         2,1310,1320,120,140,
         2,1320,1330,140,160,
         2,1330,1340,160,180,
         2,1340,1350,180,200,
         2,1350,1360,200,220,
         2,1360,1370,220,240,
         2,1370,1380,240,260,
         2,1380,1390,260,280,
         2,1390,1400,260,270,
        ];
         
         function init(){
         counter = 0;
         counter2 = 0;
         particles = [];
reset_scene();
for(var i=0;i<c.length;i+=5){
  for(var k=0;k<c[i];k++){
    var p = new particle(c[1+i],c[2+i],c[3+i],c[4+i]);
    particles.push(p);
  }
}
}

function change_color(){
  add_color = !add_color;
  if(add_color == true){
    $("input").val("Remove Color");
  }
  else{
    $("input").val("Add Color");
  }
  init();
}

function reset_scene(){
  if(add_color == false){
    ctx.fillStyle = "#212121";
    $("body").css("background","#212121");
  }
  else{
    ctx.fillStyle = "#eee";
    $("body").css("background","#eee");
  }
  ctx.fillRect(0,0,w,h);
}

function drawscene(){
  counter++;
  reset_scene();
  for(var i=0;i<particles.length;i++){
    var p = particles[i];
    //calc diff from curr to final
    if(counter < 250){
      var dX = p.fx - p.x;
      var dY = p.fy - p.y;
      var dist = Math.sqrt(dX*dX + dY*dY);
      
      if(dist<=10){
        p.vx = 0;
        p.vy = 0;
        p.ex = false;
      }
      else{
        if(dX == dY){
          
        }
        if(dY < 0){
          dY = -dY;
        }
        p.vy = dY*0.03;
        
        if(dX < 0){
          dX = -dX;
        }
        p.vx = dX*0.03;
        
      }
      
      
      if(p.x > p.fx){
        p.x -= p.vx
      }
      else{
        p.x += p.vx
      }
      
      if(p.y > p.fy){
        p.y -= p.vy
      }
      else{
        p.y += p.vy
      }
      
      p.draw();
    }
    else{
      counter2++;
      if(counter2>100000){
        counter = 0;
        counter2 = 0;
      }
      var dX = p.x - p.ox;
      var dY = p.y - p.oy;
      var dist = Math.sqrt(dX*dX + dY*dY);
      
      if(dist<=10){
        p.vx = 0;
        p.vy = 0;
        p.ex = true;
      }
      else{
        if(dX == dY){
          
        }
        if(dY < 0){
          dY = -dY;
        }
        p.vy = dY*0.03;
        
        if(dX < 0){
          dX = -dX;
        }
        p.vx = dX*0.03;
        
      }
      
      
      if(p.x > p.ox){
        p.x -= p.vx
      }
      else{
        p.x += p.vx
      }
      
      if(p.y > p.oy){
        p.y -= p.vy
      }
      else{
        p.y += p.vy
      }
      
      p.draw();
    }
  }
}

function particle(x1,x2,y1,y2){
  this.ox = Math.random()*w;
  this.oy = Math.random()*h;
  this.x = this.ox;
  this.y = this.oy;
  this.ex = true; //this particle is in exploded state
  //Final Position COORDS
  var maxx = x1;
  var minx = x2;
  this.fx = Math.floor(Math.random()*(maxx-minx+1)+minx);
  var maxy = y1;
  var miny = y2;
  this.fy = Math.floor(Math.random()*(maxy-miny+1)+miny);
  
  this.vx = 5;
  this.vy = 5;
  var max = 10;
  var min = 1;
  this.r = Math.floor(Math.random()*(max-min+1)+min);
  if(add_color == true){
    var max = 255;
    var min = 0;
    this.hue = Math.floor(Math.random()*(max-min+1)+min);
  }
  
  this.draw = function(){
    if(add_color == false){
      ctx.fillStyle = "rgba(255,255,255,0.4)";
    }
    else{
      ctx.fillStyle = 'hsla('+this.hue+', 100%, 40%, 0.4)';
    }
    ctx.beginPath();
    ctx.arc(this.x, this.y, this.r, 0, 2*Math.PI, false);
    ctx.fill();
  }
}

function animloop() {
  drawscene();
  requestAnimFrame(animloop); 
}
init();
animloop();
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console