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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <canvas id="canvas"></canvas>
              
            
!

CSS

              
                body {
  background: #000;
}

#canvas {
  position: fixed;
  background: #000;
}
              
            
!

JS

              
                
TweenLite.defaultEase = Sine.easeInOut;

var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var resolution = window.devicePixelRatio || 1;

var vw = window.innerWidth;
var vh = window.innerHeight;

var textureSize = 100;

// Create an offscreen canvas with a radial gradient
var texture = createTexture(textureSize);

// Flag to resize canvas
var resized = true;

// Array to hold orb objects
var orbs = [];

// Create a bunch of orbs
for (var i = 0; i < 200; i++) {
  orbs.push(createOrb(textureSize));
}

// Set resized flag to true on resize event
// The actual resizing will be handled in the draw function
// This will throttle resizing to animation frames
window.addEventListener("resize", function() {
  resized = true;
});

// Add listener to draw canvas on every animation frame
TweenLite.ticker.addEventListener("tick", draw);

function draw() {
  
  if (resized) {
    resize();
    resized = false;
  }
  
  // Clear the canvas
  context.clearRect(0, 0, vw, vh);
  
  // Loop through each orb
  for (var i = 0; i < orbs.length; i++) {
    orb = orbs[i];
        
    // Draw offscreen canvas at orb's x and y
    context.drawImage(texture, orb.x, orb.y);
  }
}

function createOrb(size) {
  
  var orb = {
    x: 0,
    y: 0
  };
  
  // If you want to start the orbs at a random position
  // var orb = {    
  //   x: random(vw - size),
  //   y: random(vh - size)
  // };
    
  // Start recursive function calls to animate orb x and y properties
  moveX();
  moveY();
  
  function moveX() {
    
    TweenLite.to(orb, random(3, 6), {
      x: random(vw - size),
      onComplete: moveX
    });
  }
  
  function moveY() {

    TweenLite.to(orb, random(3, 6), {
      y: random(vh - size),
      onComplete: moveY
    });
  }
  
  return orb;
}

function createTexture(size) {
  
  // Create offscreen canvas
  var canvas = document.createElement("canvas");
  var context = canvas.getContext("2d");
  var radius = size / 2;
  
  canvas.width = canvas.height = size * resolution;
  
  var gradient = context.createRadialGradient(radius, radius, 0, radius, radius, radius);
    
  gradient.addColorStop(0, "rgba(100,221,23,1)");
  gradient.addColorStop(0.2, "rgba(100,221,23,0.25)");
  gradient.addColorStop(1, "rgba(0,0,0,0)");
  
  context.fillStyle = gradient;
  context.fillRect(0, 0, size, size);  
  
  return canvas;
}

function resize() {
  
  vw = window.innerWidth;
  vh = window.innerHeight;

  canvas.width  = vw * resolution;
  canvas.height = vh * resolution;

  canvas.style.width  = vw + "px";
  canvas.style.height = vh + "px";

  context.scale(resolution, resolution);
}

function random(min, max) {
  if (max == null) { max = min; min = 0; }
  if (min > max) { var tmp = min; min = max; max = tmp; }
  return min + (max - min) * Math.random();
}
              
            
!
999px

Console