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

              
                .center
	.loading
		p loading...
	
	.content
		h1 ASCII animator

		label.ascii
			| Type something here:&nbsp;
			input[type="text" value="  .oO0Oo."]

		.output
			p

		label.speed
			| Speed:&nbsp;
			input[type="range" min="4" max="120" value="20"]

              
            
!

CSS

              
                html, body
	height: 100%

body
	display: flex
	align-items: center
	justify-content: center
	margin: 0
	font-family: monospace

.center
	display: inline-block
	margin-bottom: 40px
	text-align: center

.content
	display: none

.wf-active
	.loading
		display: none

	.content
		display: block

label
	display: block
	
.ascii
	margin-bottom: 40px

.speed
	margin-top: 40px

.output
	position: relative
	display: block
	width: 11em
	height: 11em
	margin: auto
	border: 1em solid white
	font-family: VT323, monospace
	text-align: left
	overflow: hidden
	box-shadow: 0 0 0 1px black

	p
		position: absolute
		left: 0
		bottom: -1em
		visibility: hidden
		width: 100%
		line-height: 1
		margin: 0
		word-wrap: break-word
		white-space: pre-wrap

              
            
!

JS

              
                const main = () => {
  // Adds ZERO-WIDTH-SPACEs between the characters of a word for nicer wrapping,
  // and replaces spaces with non-breaking ones.
  const spaceify =
    word => ['', ...word.replace(/ /g, '\u00A0').split(''), ''].join('\u200B');

  // DOM.
  const ascii = document.querySelector('.ascii input');
  const p = document.querySelector('.output p');
  const speed = document.querySelector('.speed input');

  // Derive the number of characters that fit on a single line.
  const charsPerLine = (() => {
    const prevHTML = p.innerHTML;
    p.textContent = '.';
    const lineHeight = p.offsetHeight;
    let charsPerLine = 0;
    for (; p.offsetHeight === lineHeight; ++charsPerLine) p.textContent += '.';
    p.innerHTML = prevHTML;
    return charsPerLine;
  })();
  p.style.minHeight = 'calc(100% + 1em)';
  p.style.visibility = 'visible';

  // State.
  let word = spaceify(ascii.value);
  let period = 40; // ~24fps.
  let timeout = period;
  let tPrev = 0;
  let i = 0;
  // Main animation loop.
  (function print (t = Date.now()) {
    const gap = tPrev && t - tPrev - timeout;

    // Clear some of the old characters if we fall well below `period`.
    if (gap > period / 2) {
      const unspaced = p.textContent.replace(/\u200B/g, '');
      const charsToKeep = 11 * charsPerLine + unspaced.length % charsPerLine;
      p.textContent = spaceify(unspaced.slice(-charsToKeep));
    }
    p.textContent += word;

    // Update state.
    tPrev = t;
    timeout = Math.max(period - gap, 0);
    setTimeout(print, timeout);
  })();

  ascii.addEventListener('keyup', e => {
    word = spaceify(ascii.value), p.textContent = '';
  });
  speed.addEventListener('input', e => {
    period = 1000 / speed.value, tPrev = 0;
  });
};

WebFont.load({
  google: {families: ['VT323']},
  active: main,
});

              
            
!
999px

Console