<div id="container">
  Lorem, ipsum dolor sit amet consectetur adipisicing elit. Fugiat maxime debitis error dicta quas! Sapiente animi dignissimos dolorem vel dolore repellendus quae quasi eos itaque officiis. Minus accusantium a adipisci.
  <div class="dividor" role="separator"></div>
  Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. 
  <div class="dividor" role="separator"></div>
  Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut.
  <div class="dividor" role="separator"></div>
</div>

<div id="config">
  <div class="config-wrap">
    <label
      id="points-count-label"
      for="points-count"
    >
      Points Count (20)
    </label>
    <input
      type="range"
      min="1"
      max="100"
      value="20"
      id="points-count"
      name="points-count"
    />
  </div>
  <div class="config-wrap">
    <label
      id="line-width-label"
      for="line-width"
    >
      Line Width (1)
    </label>
    <input
      type="range"
      min="1"
      max="10"
      step="1"
      value="1"
      id="line-width"
      name="line-width"
    />
  </div>
  <div class="config-wrap">
    <label
      id="stroke-color-label"
      for="stroke-color"
    >
      Stroke Color (#2980b9)
    </label>
    <input
      type="color"
      id="stroke-color"
      name="stroke-color"
      value="#2980b9"
    />
  </div>
</div>

<script id="c" type="text/worklet">
  const PAINTLET_NAME = 'curvy-dividor'

  class CSSPaintlet {
    static get inputProperties() {
      return [
        `--${PAINTLET_NAME}-points-count`,
        `--${PAINTLET_NAME}-line-width`,
        `--${PAINTLET_NAME}-stroke-color`
      ]
    }

    paint(ctx, paintSize, props, args) {
      const pointsCount = Number(props.get(`--${PAINTLET_NAME}-points-count`))
      const lineWidth = Number(props.get(`--${PAINTLET_NAME}-line-width`))
      const strokeColor = props.get(`--${PAINTLET_NAME}-stroke-color`)
      
      const stepX = paintSize.width / pointsCount
      
      ctx.lineWidth = lineWidth
      ctx.lineJoin = 'round'
      ctx.lineCap = 'round'
      
      ctx.strokeStyle = strokeColor
      
      const offsetUpBound = -paintSize.height / 2
      const offsetDownBound = paintSize.height / 2
      
      ctx.moveTo(-stepX / 2, paintSize.height / 2)
      for (let i = 0; i < pointsCount; i++) {
        const x = (i + 1) * stepX - stepX / 2
        const y = paintSize.height / 2 + (i % 2 === 0 ? offsetDownBound : offsetUpBound)
        const nextx = (i + 2) * stepX - stepX / 2
        const nexty = paintSize.height / 2 + (i % 2 === 0 ? offsetUpBound : offsetDownBound)
        const ctrlx = (x + nextx) / 2
        const ctrly = (y + nexty) / 2
        ctx.quadraticCurveTo(x, y, ctrlx, ctrly)
      }
      ctx.stroke()
    }
  }

  registerPaint(PAINTLET_NAME, CSSPaintlet)
</script>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: Helvetica, sans-serif;
}

#container {
  font-size: 1.4rem;
  line-height: 1.8rem;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  padding: 3rem 2rem;
}

.dividor {
  width: 100%;
  height: 20px;
  margin: 2rem auto;
  
  background: paint(curvy-dividor);
  --curvy-dividor-points-count: 20;
  --curvy-dividor-line-width: 1;
  --curvy-dividor-stroke-color: #2980B9;
}

#button {
  --grid-size: 5;
  --grid-color: #2980b9;
  
  padding: 2rem 6rem;
  color: white;
  font-size: 3rem;
  border: none;
  border-radius: 20px;
  
  background: paint(grid);
  background-repeat: no-repeat;
}

#config {
  position: fixed;
  bottom: 0;
  left: 0;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(3px);
  box-sizing: border-box;
  border-top-right-radius: 24px;
}

.config-wrap {
  margin-bottom: 0.75rem;
  color: rgba(0, 0, 0, 0.8);
}

label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}
console.clear()

const paintletCode = document.getElementById('c')

;(async function() {
  // ⚠️ Handle Firefox and Safari by importing a polyfill for CSS Pain    
  if (CSS['paintWorklet'] === undefined) {
    await import('https://unpkg.com/css-paint-polyfill')
  }

  // Explicitly define our custom CSS variable
  // Make sure that the browser treats it as a number
  
  if ('registerProperty' in CSS) {
    CSS.registerProperty({
      name: '--curvy-dividor-points-count',
      syntax: '<number>',
      inherits: false,
      initialValue: 20
    })
    CSS.registerProperty({
      name: '--curvy-dividor-line-width',
      syntax: '<number>',
      inherits: false,
      initialValue: 1
    })
    CSS.registerProperty({
      name: '--curvy-dividor-stroke-color',
      syntax: '<color>',
      inherits: false,
      initialValue: '#2980b9'
    })
  }
  
  const pointsSizeInput = document.getElementById('points-count')
  const lineWidthInput = document.getElementById('line-width')
  const strokeColorInput = document.getElementById('stroke-color')
  
  const pointsSizeLabel = document.getElementById('points-count-label')
  const lineWidthLabel = document.getElementById('line-width-label')
  const strokeColorLabel = document.getElementById('stroke-color-label')
  
  const workletElements = Array.from(document.getElementsByClassName('dividor'))
  
  pointsSizeInput.addEventListener('change', e => {
    const pointsSize = Number(e.target.value)
    pointsSizeLabel.textContent = `Points Count (${pointsSize})`
    workletElements.forEach(el => el.style.setProperty('--curvy-dividor-points-count', pointsSize))
  })
  lineWidthInput.addEventListener('change', e => {
    const lineWidth = Number(e.target.value)
    lineWidthLabel.textContent = `Line Width (${lineWidth})`
    workletElements.forEach(el => el.style.setProperty(`--curvy-dividor-line-width`, lineWidth))
  })
  strokeColorInput.addEventListener('change', e => {
    const strokeColor = e.target.value
    strokeColorLabel.textContent = `Stroke Color (${strokeColor})`
    workletElements.forEach(el => el.style.setProperty('--curvy-dividor-stroke-color', strokeColor))
  })

  // Include our paintlet using
  registerCSSPaintlet(paintletCode.textContent)
})()

function registerCSSPaintlet (sourceCode) {  CSS.paintWorklet.addModule(`data:application/javascript;charset=utf8,${encodeURIComponent(sourceCode)}`)
}
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.