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

              
                <!--
  I'm SUPER sorry if this crashes your machine.
  2D canvas wasn't built for this and I'm abusing it heavily.
-->

<div id="controls">
  <article id="article" class="hide">
    <h1>Wobble Text Generator</h1>
    <p>Some wobbly text.</p>
    <p>Hotdog because of the hot weather rn 💦</p>
    <p>
      Doesn't work in Safari (tho shows to work in the Canvas Inspector so
      idk what that's all about 🤷‍♂️)
    </p>
    <p>Part of a series of works started in June, 2019.</p>
    <a
      href="https://instagram.com/2xAA"
      target="_blank"
      rel="noopener nofollow noreferrer"
      >Instagram</a
    >
    ×
    <a
      href="https://twitter.com/_2xAA"
      target="_blank"
      rel="noopener nofollow noreferrer"
      >Twitter</a
    >
    ×
    <a
      href="https://wray.pro"
      target="_blank"
      rel="noopener nofollow noreferrer"
      >wray.pro</a
    >
  </article>
  <input type="text" id="text" />
  <input type="text" id="font" />
  <label
    ><input
      type="range"
      min="0"
      max="1"
      step="0.001"
      id="wobble-length"
    /><span>Wobble Length</span></label
  >
  <label
    ><input type="range" min="0" max="100" id="wobble-width" /><span
      >Wobble Width</span
    ></label
  >
  <label
    ><input type="range" min="0" max="1" step="0.001" id="cut-start" /><span
      >Slice Start</span
    ></label
  >
  <label
    ><input
      type="range"
      min=".01"
      max="1"
      step="0.001"
      id="cut-height"
    /><span>Slice Height</span></label
  >
  <label
    ><input type="color" id="background-color" /><span
      >Background Colour</span
    ></label
  ><br />
  <label
    ><input type="color" id="foreground-color" /><span
      >Foreground Colour</span
    ></label
  ><br />
  <div class="checkbox">
    <input type="checkbox" id="use-hdpi" />
    <label class="checkbox" for="use-hdpi"><span>Use HDPI (can be slow)</span></label>
  </div>
</div>

<button id="about">About?</button>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Six+Caps&display=swap');
@import url('https://v36p9.codesandbox.io/style.css');

html,
body {
  height: 100%;
}

body {
  position: relative;
  overflow: hidden;
  margin: 0;
}

canvas,
#controls {
  position: absolute;
}

#controls {
  z-index: 100;
  top: 10px;
  left: 10px;
  max-width: 300px;
}

input {
  display: block;
}

label input {
  display: inline;
  margin-left: 1em;
}

article {
  margin-bottom: 1em;
  text-align: center
}

#about {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 100;
}

.hide {
  display: none;
}

              
            
!

JS

              
                let text = 'HOTDOG'
let font = 'Six Caps, Proxima Nova, sans-serif'
let wobbleLength = 0.593
let cutStart = 0.531
let wobbleWidth = 6
let useHDPI = false
let dpr = 1
let cutHeight = 0.01
let cutSpacing = 0.01

let backgroundColor = '#FFFB00'
let textColor = '#FF2600'

const article = document.getElementById('article')
const aboutButton = document.getElementById('about')
aboutButton.addEventListener('click', () => {
  article.classList.toggle('hide')
})

const canvas = document.createElement('canvas')
const context = canvas.getContext('2d')

const textCanvas = document.createElement('canvas')
const textContext = textCanvas.getContext('2d')

function drawText() {
  const { width, height } = canvas
  textContext.clearRect(0, 0, width, height)
  textContext.fillStyle = textColor
  textContext.textBaseline = 'middle'
  textContext.textAlign = 'center'
  textContext.font = `${'normal'} ${128 * dpr}px ${font}`
  textContext.fillText(text, width / 2 + 5 / 2, height / 2, width - 20 * dpr)
}

function resize() {
  const { innerWidth, innerHeight, devicePixelRatio } = window
  if (useHDPI) {
    dpr = devicePixelRatio
  }

  canvas.width = textCanvas.width = innerWidth * dpr
  canvas.height = textCanvas.height = innerHeight * dpr
  canvas.style.width = `${innerWidth}px`
  canvas.style.height = `${innerHeight}px`

  drawText()
}

resize()

document.body.appendChild(canvas)

const textinput = document.getElementById('text')
textinput.value = text
textinput.addEventListener('input', e => {
  text = e.target.value
  drawText()
})

const fontInput = document.getElementById('font')
fontInput.value = font
fontInput.addEventListener('input', e => {
  font = e.target.value
})

const wobbleLengthRange = document.getElementById('wobble-length')
wobbleLengthRange.value = wobbleLength
wobbleLengthRange.addEventListener('input', e => {
  wobbleLength = parseFloat(e.target.value, 10)
})

const wobbleWidthRange = document.getElementById('wobble-width')
wobbleWidthRange.type = 'range'
wobbleWidthRange.min = 0
wobbleWidthRange.max = 100
wobbleWidthRange.value = wobbleWidth
wobbleWidthRange.addEventListener('input', e => {
  wobbleWidth = parseInt(e.target.value, 10)
})

const cutStartRange = document.getElementById('cut-start')
cutStartRange.value = cutStart
cutStartRange.addEventListener('input', e => {
  cutStart = parseFloat(e.target.value, 10)
})

const cutHeightRange = document.getElementById('cut-height')
cutHeightRange.value = cutHeight
cutHeightRange.addEventListener('input', e => {
  cutHeight = parseFloat(e.target.value, 10)
})

const backgroundColorInput = document.getElementById('background-color')
backgroundColorInput.value = backgroundColor
backgroundColorInput.addEventListener('input', e => {
  backgroundColor = e.target.value
})

const textColorInput = document.getElementById('foreground-color')
textColorInput.value = textColor
textColorInput.addEventListener('input', e => {
  textColor = e.target.value
  drawText()
})

const hdpiCheckbox = document.getElementById('use-hdpi')
hdpiCheckbox.type = 'checkbox'
hdpiCheckbox.checked = false
hdpiCheckbox.addEventListener('input', e => {
  if (e.target.checked) {
    dpr = window.devicePixelRatio
  } else {
    dpr = 1
  }

  resize()
})

window.removeEventListener('resize', resize)
window.addEventListener('resize', resize)

let raf
cancelAnimationFrame(raf)

function loop(delta) {
  raf = requestAnimationFrame(loop)
  const { width, height } = canvas

  context.fillStyle = backgroundColor

  context.fillRect(0, 0, width, height)

  const nCutStart = cutStart * height

  context.drawImage(textCanvas, 0, 0, width, nCutStart, 0, 0, width, nCutStart)

  const nWobbleLength = wobbleLength * 800 * dpr

  const sliceHeight = cutHeight * 100 * dpr

  for (let i = 0; i < nWobbleLength; ++i) {
    const mapped2 = Math.sin((i / (nWobbleLength * 2)) * (Math.PI * 2))
    const x =
      mapped2 *
      Math.sin(delta * 0.007 + (i / dpr / 10 + 1) * Math.cos(delta / 2400)) *
      wobbleWidth *
      dpr

    context.drawImage(
      textCanvas,
      x,
      nCutStart,
      width,
      sliceHeight,

      0,
      nCutStart + i,
      width,
      sliceHeight
    )
  }

  context.drawImage(
    textCanvas,
    0,
    nCutStart + sliceHeight - 1,
    width,
    height - nCutStart,

    0,
    nCutStart + nWobbleLength + sliceHeight - 1,
    width,
    height - nCutStart
  )
}

async function start() {
  await document.fonts.load('10pt "Six Caps"')
  resize()
  requestAnimationFrame(loop)
}

start()

              
            
!
999px

Console