Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <div id="catchCopy">
<h1>LET'S HYPER DRIVE</h1>
<h2>You will fly to the other side of our galaxy soon. <br>Click me!</h2>
</div>
<canvas id="universe" width="1920" height="1080"></canvas>
              
            
!

CSS

              
                html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  overflow: hidden;
  background-color: #000000;
}

#catchCopy {
  position: absolute;
  width: 100%;
  height: 100%;
  background-repeat: repeat-x;
}

#catchCopy h1 {
  font-family: sans-serif;
  font-size: 3vw;
  font-weight: bold;
  text-align: center;
  color: #fff100;
  position:absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  margin: -0.5em 0 0 -50%;
}

#catchCopy h2 {
  font-family: sans-serif;
  font-size: 0.75vw;
  text-align: center;
  color: #fff100;
  position:absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  margin: 3em 0 0 -50%;
}
              
            
!

JS

              
                const SCREEN_WIDTH = window.innerWidth;
const SCREEN_HEIGHT = window.innerHeight;
const STARS_QUANTITY = 350;

var canvas = document.getElementById('universe');
var context = canvas.getContext('2d');
var stars;
var warpFlag = 0;
var warpLocus = { value: 1 };
var tickerFlag = 1;

starsInit();
animate();

if( document.addEventListener ) {
  document.addEventListener( 'mousedown', mouseDownHandler , false );
}

function starsInit() {
  createStars();
  setInterval(starsLoop, 30);
}

function createStars() {
  stars = [];
  for (var i = 0; i < STARS_QUANTITY; i++) {

    var rdmx = (Math.random() * (SCREEN_WIDTH - 10)) + 5;
    var rdmy = (Math.random() * (SCREEN_HEIGHT - 5)) + 2.5;
    var rdmvx = (rdmx - SCREEN_WIDTH / 2) / 1000;
    var rdmvy = (rdmy - SCREEN_HEIGHT / 2) / 1000;

    var star = {
      radius: Math.random() * 1 + 0.25,
      ix: rdmx,
      iy: rdmy,
      x: rdmx,
      y: rdmy,
      vx: rdmvx,
      vy: rdmvy
    };
    stars.push(star);
  }
}

function starsLoop() {

  context.fillStyle = 'rgba(0,0,0,' + warpLocus.value + ')';
  context.fillRect(0, 0, context.canvas.width, context.canvas.height);

  for (i = 0; i < STARS_QUANTITY; i++) {
    var st = stars[i];
    var lp = { x: st.x, y: st.y };

    st.x += st.vx;
    st.y += st.vy;

    if (st.x > SCREEN_WIDTH || st.x < 0) {
      st.x = st.ix;
      st.y = st.iy;
    }
    if (st.y > SCREEN_HEIGHT || st.y < 0) {
      st.x = st.ix;
      st.y = st.iy;
    }

    if(warpFlag == 0) {
      context.fillStyle = "rgb(255,255,255)";
      context.beginPath();
      context.arc(st.x, st.y, st.radius, 0, Math.PI*2, true);
      context.closePath();
      context.fill();
    } else {
      context.beginPath();
      context.fillStyle = "rgb(255,255,255)";
      context.strokeStyle = "rgb(255,255,255)";
      context.lineWidth = st.radius;
      context.moveTo(lp.x, lp.y);
      context.lineTo(st.x, st.y);
      context.stroke();
      context.arc(st.x, st.y, st.radius, 0, Math.PI*2, true);
      context.fill();
    }
  }
}

function mouseDownHandler(e) {

  TWEEN.removeAll();

  if(warpFlag == 0) {
    warpFlag = 1;
    for (i = 0; i < STARS_QUANTITY; i++) {
      var vxValue = (stars[i].x - SCREEN_WIDTH / 2) / 10;
      var vyValue = (stars[i].y - SCREEN_HEIGHT / 2) / 10;
      new TWEEN.Tween( stars[i] )
        .to( { vx: vxValue }, 5000 )
        .easing( TWEEN.Easing.Circular.In )
        .start();
      new TWEEN.Tween( stars[i] )
        .to( { vy: vyValue }, 5000 )
        .easing( TWEEN.Easing.Circular.In )
        .start();
      new TWEEN.Tween( warpLocus )
        .to( { value: 0.05 }, 10 )
        .easing( TWEEN.Easing.Circular.In )
        .start();
    }
  } else {
    warpFlag = 0;
    for (i = 0; i < STARS_QUANTITY; i++) {
      var vxValue = (stars[i].x - SCREEN_WIDTH / 2) / 1000;
      var vyValue = (stars[i].y - SCREEN_HEIGHT / 2) / 1000;
      new TWEEN.Tween( stars[i] )
        .to( { vx: vxValue }, 5000 )
        .easing( TWEEN.Easing.Circular.Out )
        .start();
      new TWEEN.Tween( stars[i] )
        .to( { vy: vyValue }, 5000 )
        .easing( TWEEN.Easing.Circular.Out )
        .start();
      new TWEEN.Tween( warpLocus )
        .to( { value: 1 }, 5000 )
        .easing( TWEEN.Easing.Circular.Out )
        .start();
    }
  }
}

function animate()
{
  requestAnimationFrame( animate );
  TWEEN.update();
}
              
            
!
999px

Console