css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

              h1 ⸨ POND ⸩


  | viewing angle:
  input[type='range' min='0.2' max='1' step='0.1' value='0.2']

  transform: translate(-50%, -50%)
  font: 8px monospace
  position: absolute
  text-align: center
  left: 50%
  top: 50%
  display: inline-block
  font-size: 3em
  color: #efefef
    &, & + pre, & + pre + label
      color: blue
  margin: 0
label, input
  margin-top: 1.5em
  display: block
  font-size: 16px
  margin-right: auto
  margin-left: auto
              window.addEventListener('load', _ => {
	const FONT_SIZE = '72px';
	const FONT_FAMILY = 'monospace';

	// ctx.measureText() only returns width for now, so we'll just place characters
	// into a dummy span element and measure their approximate size.
	const span = document.createElement('span');
	const canvas = document.createElement('canvas');
	const ctx = canvas.getContext('2d');

	const chars = Array.from({length: 95}, (_, i) => String.fromCharCode(i + 32));

	span.style.font = `${FONT_SIZE} "${FONT_FAMILY}"`;
	span.style.visibility = 'hidden';
	span.style.position = 'absolute';
	const {w: maxWidth, h: maxHeight} = chars.reduce((max, char) => {
		span.textContent = char;
		const {width, height} = span.getBoundingClientRect();
		return {w: Math.max(max.w, width), h: Math.max(max.w, height)};
	}, {w: 0, h: 0});

	const horizontalPadding = maxWidth / 4;
	const verticalPadding = maxHeight / 4;
	const fullWidth = canvas.width = maxWidth + 2 * horizontalPadding;
	const fullHeight = canvas.height = maxHeight + 2 * verticalPadding;
	ctx.font = `${FONT_SIZE} "${FONT_FAMILY}"`;
	ctx.textBaseline = 'top';

	function getPixelWeight (char) {
		ctx.clearRect(0, 0, fullWidth, fullHeight);
		ctx.fillText(char, horizontalPadding, verticalPadding);
		// r, g, b channels will always be 0. Transparent pixels will have an alpha
		// channel of 0. So by summing `data`, we're summing the opacity of all filled-in
		// pixels. This is wildly inefficient but it gives us a dead simple, reliable
		// measure of relative size.
		return ctx.getImageData(0, 0, fullWidth, fullHeight).data.reduce((a, b) => a + b);

	const sortedChars = chars
		.map(char => ({char, weight: getPixelWeight(char)}))
		.sort(({weight: a}, {weight: b}) => a - b)
		.map(({char}) => char)
    const {sin, cos, pow} = Math;
    const [w, h] = [100, 40];

    // Get references to DOM nodes.
    const slider = document.querySelector('input');
    const pre = document.querySelector('pre');

    // Hook the slider up.
    let viewingAngle = slider.value;
    slider.addEventListener('input', () => viewingAngle = slider.value);

    // Main draw loop.
    !(function draw (t) {
      pre.textContent = Array.from({length: h}, (_, y) => Array.from({length: w}, (_, x) => sortedChars[

          (t - pow(
            (viewingAngle*pow(x-w/2, 2) + pow(y-h/2, 2)
          ), .7)) / 18

        )) * (sortedChars.length - 1))]
    ).join(' ')).join('\n');

      requestAnimationFrame(draw.bind(null, t + 1));

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