HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!--
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>
@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;
}
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()
Also see: Tab Triggers