Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ 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

              
                <!-- <audio src="https://assets.codepen.io/605876/baby-dont-hurt-me.mp3"></audio> -->
<div class="btn-scene">
  <div class="btn-jump">
    <div class="btn-tip">
      <button class="play-btn">
        <span class="play-btn__box">
          <span class="cuboid">
            <span class="cuboid__side">
              <span class="top">
                <span class="cuboid">
                  <span class="cuboid__side"></span>
                  <span class="cuboid__side"></span>
                  <span class="cuboid__side"></span>
                  <span class="cuboid__side"></span>
                  <span class="cuboid__side">
                    <span class="controls">
                      <span class="control">
                        <span class="cuboid">
                          <span class="cuboid__side"></span>
                          <span class="cuboid__side"></span>
                          <span class="cuboid__side"></span>
                          <span class="cuboid__side"></span>
                          <span class="cuboid__side"></span>
                          <span class="cuboid__side"></span>
                        </span>
                      </span>
                      <span class="control">
                        <span class="cuboid">
                          <span class="cuboid__side"></span>
                          <span class="cuboid__side"></span>
                          <span class="cuboid__side"></span>
                          <span class="cuboid__side"></span>
                          <span class="cuboid__side"></span>
                          <span class="cuboid__side"></span>
                        </span>
                      </span>
                      <span class="control play">
                        <span class="cuboid">
                          <span class="cuboid__side"></span>
                          <span class="cuboid__side"></span>
                          <span class="cuboid__side"></span>
                          <span class="cuboid__side"></span>
                          <span class="cuboid__side"></span>
                          <span class="cuboid__side"></span>
                        </span>
                      </span>
                    </span>
                  </span>
                  <span class="cuboid__side"></span>
                </span>
              </span>
              <span class="handle">
                <span class="handle__segment handle__top">
                  <span class="cuboid">
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                  </span>
                </span>
                <span class="handle__segment handle__left">
                  <span class="cuboid">
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                  </span>
                </span>
                <span class="handle__segment handle__right">
                  <span class="cuboid">
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                  </span>
                </span>
              </span>
            </span>
            <span class="cuboid__side"></span>
            <span class="cuboid__side"></span>
            <span class="cuboid__side"></span>
            <span class="cuboid__side front">
              <span class="feature brand">&lt;/&gt;</span>
              <svg class="feature bear" viewBox="0 0 969 955" fill="none" xmlns="http://www.w3.org/2000/svg">
                <circle cx="161.191" cy="332.736" r="133.191" stroke="black" stroke-width="20" />
                <circle cx="806.809" cy="332.736" r="133.191" stroke="black" stroke-width="20" />
                <circle cx="695.019" cy="600.278" r="31.4016" fill="black" />
                <circle cx="272.981" cy="600.278" r="31.4016" fill="black" />
                <path d="M564.388 724.628C564.388 756.538 526.035 792.455 483.372 792.455C440.709 792.455 402.356 756.538 402.356 724.628C402.356 692.717 440.709 676.897 483.372 676.897C526.035 676.897 564.388 692.717 564.388 724.628Z" fill="black" />
                <rect x="310.42" y="460.854" width="343.468" height="51.4986" fill="#FF1E1E" />
                <path fill-rule="evenodd" clip-rule="evenodd" d="M745.643 300.784C815.368 356.729 854.539 445.167 854.539 524.286H614.938V467.196C614.938 445.657 597.477 428.196 575.938 428.196H388.37C366.831 428.196 349.37 445.657 349.37 467.196V524.286L110.949 524.286C110.949 445.167 150.12 356.729 219.845 300.784C289.57 244.839 384.138 213.41 482.744 213.41C581.35 213.41 675.918 244.839 745.643 300.784Z" fill="black" />
              </svg>

              <div class="feature eq-wrap">
                <canvas class="eq"></canvas>
              </div>
              <span class="feature speaker speaker--left">
                <span class="tweeter"></span>
              </span>
              <span class="feature speaker speaker--right">
                <span class="tweeter"></span>
              </span>
              <span class="feature cassette-hole">
                <span class="cuboid">
                  <span class="cuboid__side"></span>
                  <span class="cuboid__side"></span>
                  <span class="cuboid__side"></span>
                  <span class="cuboid__side"></span>
                  <span class="cuboid__side"></span>
                  <span class="cuboid__side"></span>
                </span>
              </span>
              <span class="feature cassette-deck">
                <span class="feature cassette">
                  <span class="cuboid">
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side"></span>
                    <span class="cuboid__side">
                      <span class="cogs">
                        <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="cog">
                          <path stroke-linecap="round" stroke-linejoin="round" d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.324.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 011.37.49l1.296 2.247a1.125 1.125 0 01-.26 1.431l-1.003.827c-.293.24-.438.613-.431.992a6.759 6.759 0 010 .255c-.007.378.138.75.43.99l1.005.828c.424.35.534.954.26 1.43l-1.298 2.247a1.125 1.125 0 01-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.57 6.57 0 01-.22.128c-.331.183-.581.495-.644.869l-.213 1.28c-.09.543-.56.941-1.11.941h-2.594c-.55 0-1.02-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 01-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 01-1.369-.49l-1.297-2.247a1.125 1.125 0 01.26-1.431l1.004-.827c.292-.24.437-.613.43-.992a6.932 6.932 0 010-.255c.007-.378-.138-.75-.43-.99l-1.004-.828a1.125 1.125 0 01-.26-1.43l1.297-2.247a1.125 1.125 0 011.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.087.22-.128.332-.183.582-.495.644-.869l.214-1.281z" />
                          <path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
                        </svg>
                        <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="cog">
                          <path stroke-linecap="round" stroke-linejoin="round" d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.324.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 011.37.49l1.296 2.247a1.125 1.125 0 01-.26 1.431l-1.003.827c-.293.24-.438.613-.431.992a6.759 6.759 0 010 .255c-.007.378.138.75.43.99l1.005.828c.424.35.534.954.26 1.43l-1.298 2.247a1.125 1.125 0 01-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.57 6.57 0 01-.22.128c-.331.183-.581.495-.644.869l-.213 1.28c-.09.543-.56.941-1.11.941h-2.594c-.55 0-1.02-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 01-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 01-1.369-.49l-1.297-2.247a1.125 1.125 0 01.26-1.431l1.004-.827c.292-.24.437-.613.43-.992a6.932 6.932 0 010-.255c.007-.378-.138-.75-.43-.99l-1.004-.828a1.125 1.125 0 01-.26-1.43l1.297-2.247a1.125 1.125 0 011.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.087.22-.128.332-.183.582-.495.644-.869l.214-1.281z" />
                          <path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
                        </svg>

                      </span>

                    </span>
                    <span class="cuboid__side"></span>
                  </span>
                </span>
              </span>
            </span>
            <span class="cuboid__side"></span>
          </span>
        </span>
        <span class="play-btn__text">
          <span class="txt">
            <svg aria-hidden=true xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6">
              <path fill-rule="evenodd" d="M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z" clip-rule="evenodd" />
            </svg>
            Play
          </span>
        </span>
      </button>
    </div>
  </div>
  <div class="btn-shadow"></div>
</div>
              
            
!

CSS

              
                *,
*:after,
*:before {
  box-sizing: border-box;
  transform-style: preserve-3d;
}

:root {
  --handle-girth: 10;
  --handle-multiplier: 0.5px;
  --surface-1: hsl(210 10% 50%);
  --surface-2: hsl(210 10% 40%);
  --surface-3: hsl(210 10% 30%);
  --surface-4: hsl(210 10% 20%);
  --surface-5: hsl(210 10% 10%);
  --speaker: hsl(0 0% 6%);
  --trim: hsl(0 0% 90%);
  --tweeter: hsl(0 0% 30%);
  --handle: hsl(0 0% 8%);
  /*	--handle: var(--trim);*/
  --label: hsl(0 0% 98%);
  --top: hsl(210 10% 65%);
  --front: var(--surface-1);
  --grill: hsl(0 0% 10%);
  --back: var(--surface-3);
  --cassette: hsl(0 0% 0%);
  --control: hsl(210 80% 80%);
  --play: hsl(10 80% 80%);
  --accent: hsl(10 50% 50%);
  --drawer: hsl(210 10% 6%);
}

body {
  background: hsl(210 34% 84%);
  display: grid;
  place-items: center;
  min-height: 100vh;
  font-family: "Google Sans", sans-serif, system-ui;
}

span {
  display: block;
}

.play-btn {
  position: relative;
  border: 0;
  padding: 0;
  background: none;
}

.play-btn__text {
  color: white;
  padding: 1rem 2rem;
  background: var(--front);
}

.txt {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.play-btn__text svg {
  width: 24px;
}

.play-btn__box {
  --depth: var(--boom-depth);
  display: none;
  position: absolute;
  inset: 0;
  color: var(--surface-3);
  opacity: 1;
  transform: translate3d(0, 0, -1px);
  /*	transform: translate3d(0, 0, calc(var(--boom-depth) * -0.5px));*/
}

.play-btn__box > .cuboid > .cuboid__side:nth-of-type(2):after {
  content: "";
  height: 16%;
  width: 60%;
  position: absolute;
  bottom: 6%;
  right: 0;
  background: repeating-linear-gradient(
    0deg,
    var(--grill) 0 20%,
    transparent 20% 40%
  );
}

.speaker {
  position: absolute;
  height: 55%;
  aspect-ratio: 1;
  border-radius: 50%;
  bottom: 0;
  background: conic-gradient(
      from 190deg,
      hsl(0 0% 20%) 0 45deg,
      transparent 0deg
    ),
    var(--speaker);
  border: 4px solid var(--trim);
}

.tweeter {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: 50%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--tweeter);
}

.controls {
  position: absolute;
  bottom: 10%;
  left: 10%;
  height: 16%;
  display: flex;
  gap: 4px;
}

.bear {
  position: absolute;
  left: 5%;
  top: 5%;
  width: 20%;
  rotate: -30deg;
}

.brand {
  color: var(--trim);
  text-shadow: 2px 2px red;
  position: absolute;
  right: 4%;
  top: 8%;
  font-size: 1rem;
  font-family: monospace;
  font-weight: bold;
}

.brand:after {
  content: "";
  position: absolute;
  top: 110%;
  width: 100%;
  aspect-ratio: 2 / 1;
  background: var(--label);
  right: 0;
}

.control {
  --depth: 20;
  height: 100%;
  aspect-ratio: 1;
  color: var(--control);
}

.control:nth-of-type(1) {
  color: hsl(130 80% 80%);
}

.cogs {
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  height: 40%;
  width: 70%;
  display: flex;
  justify-content: space-between;
}

.cogs:after {
  content: "";
  font-family: cursive;
  background: white;
  height: 0.5rem;
  position: absolute;
  top: 110%;
  width: 80%;
  left: 50%;
  overflow: hidden;
  translate: -50% 0;
}

.cog {
  fill: black;
  stroke: var(--trim);
}

.control:nth-of-type(3) {
  aspect-ratio: 2 / 1;
  color: var(--play);
}

.speaker--left {
  left: 0;
  translate: 10% -10%;
}

.speaker--right {
  right: 0;
  translate: -10% -10%;
}

.cassette-hole {
  --depth: 20;
  color: var(--surface-4);
  aspect-ratio: 4 / 2.5;
  width: 25%;
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% 0;
  transform-origin: 50% 100%;
  transform: translate3d(0, 0, -11px);
}

.cassette-hole .cuboid__side:nth-of-type(5) {
  display: none;
}

.cassette {
  --depth: 10;
  color: var(--cassette);
  width: 90%;
  aspect-ratio: 4 / 2.5;
  transform: translate3d(0, 0, -11px);
}

.cassette-deck {
  aspect-ratio: 4 / 2.5;
  background: linear-gradient(
      90deg,
      var(--drawer) 10px,
      transparent 10px calc(100% - 10px),
      var(--drawer) calc(100% - 10px)
    ),
    linear-gradient(
      0deg,
      var(--drawer) 10px,
      transparent 10px calc(100% - 10px),
      var(--drawer) calc(100% - 10px)
    ),
    linear-gradient(
      -65deg,
      transparent 70%,
      hsl(0 0% 100% / 0.5) 70.5% 80%,
      transparent 80.5% 82%,
      hsl(0 0% 100% / 0.5) 82.5% 84%,
      transparent 84.5%
    ),
    hsl(0 0% 100% / 0.2);
  display: grid;
  place-items: center;
  width: 25%;
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% 0;
  transform-origin: 50% 100%;
  transform: rotateX(0deg);
}

.cassette .cuboid__side:nth-of-type(5) {
  background: linear-gradient(
      90deg,
      transparent 60%,
      red 60.5% 70.5%,
      transparent 71%
    ),
    var(--cassette);
}

.cassette-deck:after,
.cassette-deck:before {
  content: "";
  position: absolute;
  bottom: 0;
  height: 85%;
  width: 10%;
  background: var(--drawer);
}

.cassette-deck:after {
  left: 100%;
  transform-origin: 0 50%;
  transform: rotateY(90deg);
  clip-path: polygon(0 0, 100% 25%, 100% 100%, 0 100%);
}

.cassette-deck:before {
  right: 100%;
  transform-origin: 100% 50%;
  transform: rotateY(-90deg);
  clip-path: polygon(0 25%, 100% 0%, 100% 100%, 0 100%);
}

.play-btn > .cuboid {
  color: var(--back);
}

.play-btn__box > .cuboid > .cuboid__side:nth-of-type(5) {
  filter: none;
  height: 100%;
  width: 100%;
  transform: translate3d(0, 0, calc(var(--depth, 20) * 0.5px));
  top: 0;
  left: 0;
  background: linear-gradient(
      180deg,
      var(--front) 50%,
      transparent 50% 77%,
      var(--front) 77%
    ),
    linear-gradient(
      90deg,
      var(--front) 38.5%,
      transparent 38.5% 62.5%,
      var(--front) 62.5%
    ),
    hsl(0 0% 50% / var(--fill, 0));
}

.eq-wrap {
  width: 25%;
  aspect-ratio: 16 / 6;
  top: 20%;
  position: absolute;
  left: 50%;
  translate: -50% 0;
}

.eq {
  border: 4px solid black;
  aspect-ratio: 16 / 6;
  width: 100%;
  background: black;
}

.eq-wrap:after {
  content: "";
  position: absolute;
  inset: 0;
  border: 4px solid black;
  background: linear-gradient(
    -65deg,
    transparent 50%,
    hsl(0 0% 100% / 0.5) 50.5% 60%,
    transparent 60.5% 62%,
    hsl(0 0% 100% / 0.5) 62.5% 64%,
    transparent 64.5%
  );
}

.top {
  position: absolute;
  bottom: 10%;
  width: calc(90% - (2 * (var(--handle-girth) * 1px)));
  height: 90%;
  --depth: calc(var(--active) * 40);
  left: 50%;
  translate: -50% 0;
  color: var(--top);
  transform: translate3d(0, 0, -20px);
}

.top .cuboid__side:nth-of-type(2) {
  background: var(--back);
}

.play-btn__backdrop {
  background: var(--surface);
  position: absolute;
  inset: 0;
  z-index: 0;
}

.play-btn__box > .cuboid > .cuboid__side:nth-of-type(6) {
  background: linear-gradient(
      0deg,
      var(--back) calc(100% - (var(--handle-girth) * 1px)),
      transparent calc(100% - (var(--handle-girth) * 1px))
    ),
    linear-gradient(90deg, var(--back) 5%, transparent 5% 95%, var(--back) 95%);
}

.top > .cuboid > .cuboid__side:nth-of-type(5):after {
  content: "";
  position: absolute;
  right: 10%;
  top: 0;
  background: repeating-linear-gradient(
    90deg,
    var(--grill) 0 5%,
    transparent 5% 10%
  );
  height: 30%;
  width: 36%;
}

.play-btn__box > .cuboid > .cuboid__side:nth-of-type(1) {
  background: linear-gradient(0deg, var(--top) 10%, transparent 10%),
    linear-gradient(90deg, var(--top) 5%, transparent 5% 95%, var(--top) 95%);
}

.handle {
  color: var(--handle);
  height: 80%;
  position: absolute;
  top: 0;
  left: 50%;
  translate: -50% 0;
  width: 90%;
  transform-origin: 50% 100%;
  transform: translate3d(0, 0, calc(var(--handle-girth) * -0.5px)) rotateX(0deg);
}

.handle__segment {
  --depth: calc(var(--active) * var(--handle-girth));
  position: absolute;
}

.handle__left {
  width: calc(var(--handle-girth) * var(--handle-multiplier));
  height: 100%;
  left: 0;
}
.handle__right {
  width: calc(var(--handle-girth) * var(--handle-multiplier));
  height: 100%;
  right: 0;
}

.handle__top {
  height: calc(var(--handle-girth) * var(--handle-multiplier));
  width: 100%;
}

.btn-scene {
  --active: 0;
  position: relative;
}

.btn-shadow {
  width: 100%;
  aspect-ratio: 4 / 1;
  background: hsl(0 0% 10%);
  top: 100%;
  position: absolute;
  translate: 0 -50%;
  transform: rotateX(90deg) translate(0, -1px);
}

/* Cuboid related stuff */
.cuboid {
  --color-range-lower: 180;
  --color-range-upper: 340;
  --step: calc(
    (var(--color-range-upper) - var(--color-range-lower)) / var(--count)
  );
  --alpha: calc(1 - ((0.85 / var(--count)) * var(--index)));
  --color: hsl(
    calc(var(--color-range-lower) + (var(--step) * var(--index))) 80% 60% /
      var(--alpha)
  );
  --bg: currentColor;
}

/* Cuboid boilerplate code */
.cuboid {
  width: 100%;
  height: 100%;
  position: relative;
}
.cuboid__side {
  background: var(--bg);
  filter: brightness(var(--b, 1));
  border: calc(var(--size) * 0.0075vmin) solid var(--color);
  position: absolute;
}
.cuboid__side:nth-of-type(1) {
  --b: 1.1;
  filter: none;
  height: calc(var(--depth, 20) * 1px);
  width: 100%;
  top: 0;
  /*  perspective: 100vmin;*/
  transform: translate(0, -50%) rotateX(90deg);
}
.cuboid__side:nth-of-type(2) {
  --b: 0.9;
  height: 100%;
  width: calc(var(--depth, 20) * 1px);
  top: 50%;
  right: 0;
  transform: translate(50%, -50%) rotateY(90deg);
}
.cuboid__side:nth-of-type(3) {
  --b: 0.5;
  width: 100%;
  height: calc(var(--depth, 20) * 1px);
  bottom: 0;
  transform: translate(0%, 50%) rotateX(90deg);
}
.cuboid__side:nth-of-type(4) {
  --b: 1;
  height: 100%;
  width: calc(var(--depth, 20) * 1px);
  left: 0;
  top: 50%;
  transform: translate(-50%, -50%) rotateY(90deg);
}
.cuboid__side:nth-of-type(5) {
  filter: none;
  height: 100%;
  width: 100%;
  transform: translate3d(0, 0, calc(var(--depth, 20) * 0.5px));
  top: 0;
  left: 0;
  /*  perspective: 100vmin;*/
}
.cuboid__side:nth-of-type(6) {
  --b: 1.2;
  height: 100%;
  width: 100%;
  transform: translate3d(0, 0, calc(var(--depth, 20) * -0.5px)) rotateY(180deg);
  top: 0;
  left: 0;
}

              
            
!

JS

              
                import gsap from "https://cdn.skypack.dev/[email protected]";

const BUTTON = document.querySelector("button");
const AUDIO = new Audio(
  "https://cdn.streamelements.com/uploads/e60302a6-b7b8-4464-864c-b911b5403010.mp3"
);
// const AUDIO = document.querySelector('audio')
AUDIO.crossOrigin = "anonymous";

const CONFIG = {
  FADE: 2,
  BARS: 16,
  DURATION: 0.6,
  ANGLE: -22,
  MULTI: 2.6,
  FFT: 32
};
// Stuff for audio...
// Load MP3 file
// Create audio context and analyser node
let AUDIO_CONTEXT;
let SOURCE;
let ANALYSER;
// Min number of bars you can get is 16. If you want less, like 4, take the average of groups of 4.
// Or only use the first 4 or 5.
// ANALYSER.fftSize = CONFIG.FFT;
// // Connect audio source to analyser
// SOURCE.connect(ANALYSER);
// ANALYSER.connect(AUDIO_CONTEXT.destination);
// Create array to hold frequency data
let BUFFER_LENGTH;
let FREQ_ARR;
let TIME_ARR;

// Create canvas element and context
const canvas = document.querySelector(".eq");
const canvasContext = canvas.getContext("2d");

let grd;
let barWidth;
let barHeightMultiplier;
let VIZ_TL;
let run = 0;

const TRACK = [];
const BOUNDS = BUTTON.getBoundingClientRect();

gsap.defaults = {
  ease: "power4.out"
};

gsap.set(BUTTON, { "--boom-depth": 0 });
gsap.set(".play-btn__box", { display: "block" });

const COG_PLAY = gsap
  .timeline({
    paused: true
  })
  .to(".cog", {
    rotate: 360,
    repeat: -1,
    ease: "none",
    duration: 3
  });

BUTTON.addEventListener("click", () => {
  BUTTON.disabled = true;

  gsap
    .timeline({
      onComplete: () => {
        if (!AUDIO_CONTEXT) {
          AUDIO_CONTEXT = new AudioContext();
          SOURCE = AUDIO_CONTEXT.createMediaElementSource(AUDIO);
          ANALYSER = AUDIO_CONTEXT.createAnalyser();
          // Min number of bars you can get is 16. If you want less, like 4, take the average of groups of 4.
          // Or only use the first 4 or 5.
          ANALYSER.fftSize = CONFIG.FFT;
          // Connect audio source to analyser
          SOURCE.connect(ANALYSER);
          ANALYSER.connect(AUDIO_CONTEXT.destination);
          // Create array to hold frequency data
          BUFFER_LENGTH = ANALYSER.frequencyBinCount;
          FREQ_ARR = new Uint8Array(BUFFER_LENGTH);
          TIME_ARR = new Uint8Array(BUFFER_LENGTH);
        }
        canvas.width = canvas.offsetWidth;
        canvas.height = canvas.offsetHeight;
        barWidth = canvas.width / CONFIG.BARS;
        barHeightMultiplier = canvas.height / 255;
        grd = canvasContext.createLinearGradient(0, 0, 0, canvas.height);
        grd.addColorStop(0, "red");
        grd.addColorStop(1 / 3, "red");
        grd.addColorStop(1 / 3, "yellow");
        grd.addColorStop(2 / 3, "yellow");
        grd.addColorStop(2 / 3, "green");
        grd.addColorStop(1, "green");
        canvasContext.fillStyle = grd;
        AUDIO.pause();
        AUDIO.currentTime = 0;
        AUDIO.volume = 0;
        AUDIO.play();
        COG_PLAY.play();
      }
    })
    .set(".btn-jump", {
      rotateY: 0
    })
    .set(".front", {
      clearProps: "background"
    })
    .set(".btn-shadow", {
      opacity: 0
    })
    .to(
      ".btn-scene",
      {
        transform: `rotateX(${CONFIG.ANGLE}deg) rotateY(${CONFIG.ANGLE}deg)`,
        duration: CONFIG.DURATION,
        "--active": 1
      },
      0
    )
    .to(
      ".play-btn__text",
      {
        opacity: 0,
        duration: CONFIG.DURATION,
        z: BOUNDS.width * CONFIG.MULTI * 0.125
      },
      0
    )
    .to(
      ".cassette-deck",
      {
        rotateX: -45,
        duration: CONFIG.DURATION
      },
      0
    )
    .to(
      BUTTON,
      {
        duration: CONFIG.DURATION,
        "--boom-depth": BOUNDS.width * CONFIG.MULTI * 0.25,
        width: BOUNDS.width * CONFIG.MULTI,
        height: BOUNDS.width * CONFIG.MULTI * 0.56
      },
      0
    )
    .to(
      ".btn-shadow",
      {
        opacity: 1,
        duration: CONFIG.DURATION * 0.5,
        ease: "bounce.out"
      },
      CONFIG.DURATION * 0.5
    )
    .to(
      ".btn-jump",
      {
        duration: CONFIG.DURATION * 0.5,
        y: -200
      },
      0
    )
    .to(
      ".btn-jump",
      {
        duration: CONFIG.DURATION * 0.5,
        ease: "bounce.out",
        y: 0
      },
      CONFIG.DURATION * 0.5
    )
    .to(
      ".btn-jump",
      {
        duration: CONFIG.DURATION * 0.5,
        rotateY: -360
      },
      0
    )
    .to(
      ".feature",
      {
        opacity: 1,
        duration: CONFIG.DURATION * 0.5
      },
      0
    )
    .to(".handle", {
      delay: 0.5,
      rotateX: -90,
      duration: CONFIG.DURATION * 0.5
    })
    .to(".cassette-deck", {
      rotateX: 0,
      duration: CONFIG.DURATION * 0.5
    })
    .to(".play", {
      delay: CONFIG.DURATION * 0.25,
      z: -5,
      duration: CONFIG.DURATION * 0.25
    });
});

const VIZ = () => {
  // Generate the first time then reuse
  // Get frequency data
  ANALYSER.getByteFrequencyData(FREQ_ARR);
  ANALYSER.getByteTimeDomainData(TIME_ARR);
  // Clear canvas
  canvasContext.clearRect(0, 0, canvas.width, canvas.height);

  const BARS = FREQ_ARR.slice(0, CONFIG.BARS);

  // Keep the Array in memory so we don't have to create it again.
  // TRACK.push(BARS)

  BARS.forEach((bar, index) => {
    // let barHeight = gsap.utils.snap(255 / 10, BARS[index] * barHeightMultiplier);
    let barHeight = gsap.utils.snap(
      255 / 25,
      BARS[index] * barHeightMultiplier
    );
    // But, I actually want to step this so it's gonna be the nearest divisor of 5.
    // console.info({ barHeight })
    gsap.set(".tweeter", {
      scale: gsap.utils.mapRange(128, 255, 1, 1.35)(TIME_ARR[0])
    });
    canvasContext.fillRect(
      index * barWidth,
      canvas.height - barHeight,
      barWidth,
      barHeight
    );
  });
};

VIZ_TL = gsap.timeline();
const FADE_IN_OUT = () => {
  gsap.to(AUDIO, {
    volume: 1,
    duration: CONFIG.FADE,
    repeat: 1,
    yoyo: true,
    repeatDelay: AUDIO.duration - 2 * CONFIG.FADE
  });
  run = 0;
  gsap.ticker.add(VIZ);
};

const RESET = () => {
  // Can it remove it if it isn't there?
  gsap.delayedCall(CONFIG.FADE * 0.5, () => {
    gsap.ticker.remove(VIZ);
    COG_PLAY.pause();
    gsap
      .timeline({
        onComplete: () => {
          BUTTON.disabled = false;
        }
      })
      .set(".btn-shadow", {
        opacity: 0
      })
      .to(".play", {
        z: 0,
        duration: CONFIG.DURATION * 0.25
      })
      .to(".handle", {
        rotateX: 0,
        duration: CONFIG.DURATION * 0.25
      })
      .to(BUTTON, {
        duration: CONFIG.DURATION * 0.5,
        width: BOUNDS.width,
        height: BOUNDS.height
      })
      .to(
        ".btn-scene",
        {
          "--active": 0,
          duration: CONFIG.DURATION * 0.25
        },
        "<"
      )
      .to(
        ".btn-scene",
        {
          duration: CONFIG.DURATION * 0.5,
          transform: "rotateX(0deg) rotateY(0deg)"
        },
        "<"
      )
      .to(
        ".feature",
        {
          opacity: 0,
          duration: CONFIG.DURATION * 0.15
        },
        "<"
      )
      .to(
        ".btn-jump",
        {
          rotateY: 0,
          duration: CONFIG.DURATION * 0.5
        },
        "<"
      )
      .to(
        ".front",
        {
          background: "var(--front)",
          duration: CONFIG.DURATION * 0.25
        },
        "<"
      )
      .to(BUTTON, {
        "--boom-depth": 0,
        duration: CONFIG.DURATION * 0.25
      })
      .to(
        ".play-btn__text",
        {
          opacity: 1,
          z: 0,
          duration: CONFIG.DURATION * 0.25
        },
        "<"
      )
      .timeScale(1);
  });
};

// Bind things up
AUDIO.addEventListener("play", FADE_IN_OUT);
AUDIO.addEventListener("ended", RESET);

              
            
!
999px

Console