cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <div id="waves-container" class="waves"></div>
<div id="graph-container" class="graph"></div>
            
          
!
            
              $canvas-count: 10;
$canvas-width: 400;
$animation-dur: 15s;

html, body {
  height: 100%;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  perspective: 5000px;
}

.waves, .graph {
  position: absolute;
  height: #{$canvas-width}px;
  transform-style: preserve-3d;
  background: rgba(black, .05);
}

.waves {
  width: #{$canvas-width}px;
  animation: waves-container $animation-dur infinite;

  canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    @for $i from 0 through $canvas-count {
      &:nth-child(#{$i}) {
        animation: canvas-#{$i} $animation-dur infinite;
      }
    }
  }
}

.graph {
  animation: graph-container $animation-dur infinite;
  transform:
    translateX(37.5%)
    rotateX(-27.5deg)
    rotateY(45deg);
  
  canvas {
    animation: graph $animation-dur infinite;
  }
}

@keyframes waves-container {
  from, 10%, 90%, to {
    transform: none;
  }

  17.5%, 82.5% {
    transform:
      translateX(-37.5%)
      rotateX(-27.5deg)
      rotateY(-45deg);
  }
}

@for $i from 0 through $canvas-count {
  @keyframes canvas-#{$i} {
    from, 20%, 80%, to {
      transform: translate(-50%, -50%);
    }
    27.5%, 72.5% {
      transform:
        translate3d(
          -50%, 
          -50%, 
          #{ ($i - 1) * -($canvas-width / $canvas-count * 1px) }
        );
    }
  }
}

@keyframes graph-container {
  from, 20%, 80%, to {
    width: 0;
    opacity: 0;
  }
  27.5%, 72.5% {
    width: #{$canvas-width}px;
    opacity: 1;
  }
}

@keyframes graph {
  from, 30%, 75%, to {
    opacity: 0;
  }
  37.5%, 67.5% {
    opacity: 1;
  }
}
            
          
!
            
              var canvasCount = 10
var canvasWidth = 400
var container = document.getElementById('waves-container')
var graphContainer = document.getElementById('graph-container')

function drawSin(ctx, waveLength, x = 1, y) {
  var i = 0
  while (i++ < x) {
    ctx.fillRect(
      i,
      y + Math.sin((i / waveLength)) * waveLength,
      1, 1
    )
  }
}

var canvases = new Array(canvasCount)
  .join(' ')
  .split(' ')
  .map((c, i) => {
    var canvas = document.createElement('canvas')
    canvas.width = canvasWidth
    canvas.height = canvasWidth
    container.appendChild(canvas)
    return canvas
  })

var contexts = canvases.map(c => c.getContext('2d'))
contexts.forEach(ctx => ctx.fillStyle = 'red')

var maxWaveLength = 60

var graph = document.createElement('canvas')
graph.width = canvasWidth
graph.height = canvasWidth
graphContainer.appendChild(graph)

var graphCtx = graph.getContext('2d')
graphCtx.strokeStyle = 'blue'
graphCtx.lineWidth = 2

var graphBaseY = canvasWidth / 2 + maxWaveLength / 2

var i = 0

requestAnimationFrame(function draw() {
  graphCtx.clearRect(0, 0, canvasWidth, canvasWidth)
  graphCtx.beginPath()
  graphCtx.moveTo(0, graphBaseY)
  graphCtx.lineTo(canvasWidth, graphBaseY)
  graphCtx.stroke()
  
  i += 0.003
  
  contexts.forEach((ctx, index) => {
    ctx.clearRect(0, 0, canvasWidth, canvasWidth)

    var waveLength = maxWaveLength / Math.pow(
      index + 1,
      1 + Math.sin(i)
    )

    drawSin(
      ctx,
      waveLength,
      canvasWidth,
      canvasWidth / 2
    )

    graphCtx.beginPath()

    graphCtx.moveTo(
      index * (canvasWidth / canvasCount),
      graphBaseY
    )

    graphCtx.lineTo(
      index * (canvasWidth / canvasCount),
      graphBaseY - waveLength * 2
    )

    graphCtx.stroke()
  })

  requestAnimationFrame(draw)
})
            
          
!
999px
Loading ..................

Console