123

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.

            
              <canvas id=c></canvas>
<div id=overlay></div>
<p> followers on codepen: thank <span>you</span> so much! </p>
            
          
!
            
              canvas {
  position:absolute;
  top: calc( 50vh - 200px );
  left: calc( 50vw - 300px );
  
  background-color: #111;
}
#overlay {
  position:absolute;
  top: calc( 50vh - 200px );
  left: calc( 50vw - 300px );
  width: 600px;
  height: 400px;
  
  background: radial-gradient( ellipse 300px 200px at 300px 200px,  rgba( 0, 0, 0, 0 ), rgba( 0, 0, 0, .2 ), rgba( 0, 0, 0, .5 ) );
}
body {
  background-color: #090909;
}
p {
  font: 20px Verdana;
  color: hsl( 230, 50%, 40% );
  text-shadow: 0 0 2px hsl( 230, 50%, 40% );
  
  position: absolute;
  top: calc( 50vh + 160px );
  left: 0;
  margin: 0 0;
  width: 100vw;
  text-align: center;
}
span {
  
  font-size: 24px;
  color: hsl(230, 50%, 55%)
}
            
          
!
            
              /*
 * This is my 100 followers special!
 * Thanks to everyone for showing
 * interesting in what I do, I really
 * apreciate it! Hope you enjoy the pen!
 *
 */

var w = c.width = 600,
    h = c.height = 400,
    ctx = c.getContext( '2d' ),
    
    particleCount = 300,
    spawnProb = 1,
    hueStart = 200,
    hueEnd = 260,
    minSize = 5,
    maxSize = 15,
    speedMultiplier = .1,
    alphaChanger = .05,
    
    one = {
      x: 90, w: 55,
      y: 90, h: 210
    },
    r1 = 50,
    r2 = 90,
    f0 = { // first zero
      x: 252, 
      y: 200,
    },
    s0 = { // second zero
      x: 410, 
      y: 200,
    }
    
    particles = [],
    squareR1 = r1 * r1,
    squareR2 = r2 * r2,
      
    leftest = one.x,
    rightest = s0.x + r2,
    highest = Math.min( one.y, f0.y - r2, s0.y - r2 ),
    lowest = Math.max( one.y + one.w, f0.y + r2, s0.y + r2 ) + maxSize,
    
    isInText = function( x, y ) {
      
      // check if point is in 1, which is a rectangle
      if( !( x < one.x || x > one.x + one.w ||
             y < one.y || y > one.y + one.h) )
        	return true;
      
      // check if point is in the 0s
      else {
        
        var dX = x - f0.x, // distance in the X from First zero
            dY = y - f0.y, // distance in the Y from First zero
            squareDist = dX * dX + dY * dY;
        
        if( squareDist > squareR1 && squareDist < squareR2 )
          return true;
        
            dX = x - s0.x; // second zero
            dY = y - s0.y;
            squareDist = dX * dX + dY * dY;
        
        if( squareDist > squareR1 && squareDist < squareR2 )
          return true;
      }
      
      return false;
    };

function loop() {
  
  window.requestAnimationFrame( loop );
  
  ctx.globalCompositeOperation = 'source-over';
  ctx.fillStyle = '#111';
  ctx.fillRect( 0, 0, w, h );
  ctx.globalCompositeOperation = 'lighter';
  
  step( true );
}
function step( render ) {
  
  if( particles.length < particleCount && Math.random() < spawnProb )
    particles.push( new Particle );
  
  particles.map( function( par ) { par.step( render ); } );
  
}

function Particle() {
  
  this.reset();
}
Particle.prototype.reset = function() {
  
  this.bigness = 0;
  this.hue = rand( hueStart, hueEnd ) |0;
  this.size = rand( minSize, maxSize ) |0;
  
  this.x = rand( leftest, rightest ) |0;
  this.y = highest - this.size;
  
  this.gradient = ctx.createRadialGradient( 0, 0, 0, 0, 0, this.size * 2);
  this.gradient.addColorStop( 0, 'hsla(hue, 80%, 50%, .8)'.replace( 'hue', this.hue ) );
  this.gradient.addColorStop( .5, 'hsla(hue, 80%, 50%, .8)'.replace( 'hue', this.hue ) );
  this.gradient.addColorStop( 1, 'hsla(hue, 80%, 50%, .0)'.replace( 'hue', this.hue ) );
}
Particle.prototype.step = function( render ) {
  
  this.y += speedMultiplier * this.size;
  
  if( this.y - this.size > lowest ) this.reset();
  
  if( isInText( this.x, this.y ) ){
    
    if( this.bigness < 1 ) this.bigness += alphaChanger; 
  } else if( this.bigness > 0 ) this.bigness -= alphaChanger;
  
  if( render && this.bigness > 0 ) {
    
    ctx.fillStyle = this.gradient;
    ctx.translate( this.x, this.y );
    ctx.scale( this.bigness, this.bigness );
    ctx.beginPath();
    ctx.arc(0, 0, this.size * 2, 0, Math.PI * 2);
    ctx.fill();
    ctx.scale( 1/this.bigness, 1/this.bigness );
    ctx.translate( -this.x, -this.y );
    
  }
}


function rand( min, max ) {
	
  return Math.random() * ( max - min ) + min;
}

for( var n = 0; n < 200; ++n )
  step( false ); // just to have the thing already loaded


loop();

// boundary test 
/*
ctx.fillStyle = ctx.strokeStyle = 'white';
ctx.fillRect( one.x, one.y, one.w, one.h );
ctx.beginPath();
ctx.arc( f0.x, f0.y, r2, 0, Math.PI * 2, true);
ctx.arc( f0.x, f0.y, r1, 0, Math.PI * 2, false);
ctx.fill();
ctx.beginPath();
ctx.arc( s0.x, s0.y, r2, 0, Math.PI * 2, true);
ctx.arc( s0.x, s0.y, r1, 0, Math.PI * 2, false);
ctx.fill();
*/
            
          
!
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