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. 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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div id="content">
  <canvas id="parsec" width="100" height="100"></canvas>
</div>
              
            
!

CSS

              
                @font-face {
  src: url("../assets/TI99Basic.ttf");
  font-family: "Basic";
  font-weight: normal;
  font-style: normal;
}

* {
  margin: 0;
  padding: 0;
  border: 0;
  font-family: "Basis33", monospace;
}

body {
  margin: 0;
  overflow: hidden;
}

span {
  font-style: italic;
}

canvas {
  background-color: black;
}

#content::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.15),
    rgba(0, 0, 0, 0.15) 1px,
    transparent 1px,
    transparent 2px
  );
}
  
              
            
!

JS

              
                let lastTimestamp = 0;

function main(timestamp: number) {
  const delta = timestamp - lastTimestamp;
  lastTimestamp = timestamp;

  // We'll need the canvas context for rendering.
  const canvas = document.getElementById("parsec");
  const context = canvas.getContext("2d", { alpha: false });

  // Fill the screen, always set the width, this trick clears the canvas
  canvas.width = document.body.clientWidth;
  if (canvas.height != document.documentElement.clientHeight) {
    canvas.height = document.documentElement.clientHeight;
  }

  // Set context transformation. This let us operate with a simpler 640x480
  // coordinate system.
  context.setTransform(canvas.width / 640, 0, 0, canvas.height / 480, 0, 0);

  // Update the game state...
  updateGameState(timestamp, delta);
  // ...then render the scene
  renderer(context);

  // Finally, request the next animation frame
  window.requestAnimationFrame(main);
}

// Start the main loop when we're done loading the page
window.onload = () => {
  window.requestAnimationFrame(main);
};

let stars: { x: number; y: number; speed: number }[] = [];
function renderer(context: CanvasRenderingContext2D) {
  context.fillStyle = "#000000";
  context.fillRect(0, 0, 640, 480);

  context.fillStyle = "#cccccc";
  stars.forEach(star => context.fillRect(star.x, star.y, 2, 2));
}

function updateGameState(timestamp: number, delta: number) {
  if (stars.length === 0) {
    // Initial run, let's create some stars
    for (let i = 0; i < 100; i++) {
      stars.push({
        x: Math.random() * 640,
        y: Math.random() * 400,
        speed: Math.random() * -200
      });
    }
  }

  // Update the stars
  stars = stars.map(star => {
    const newX = star.x + (star.speed * delta) / 1000;
    return { ...star, x: newX > 0 ? newX : 640 };
  });
}

              
            
!
999px

Console