JSFiddle - React, Tailwind, and code Playground

by joshmoto

HTML

<div id="zone">
  <div id="pythagorean-x"></div>
  <div id="pythagorean-y"></div>
  <div id="area"></div>
  <div id="arrow">
    <div id="hypotenuse">h=0px</div>
  </div>
  <div id="angle">r=0°</div>
  <div id="x">x=0px</div>
  <div id="y">y=0px</div>
</div>

SCSS

:root {
  --hsl: hsl(0, 100%, 50%);
}

#zone {
  background: black;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  cursor: crosshair;
  overflow: hidden;
}

#arrow {
  width: 2px;
  height: 0px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: bottom center;
  transition: height 0.05s ease;
  transform: translate(-1px, -100%);
  background: linear-gradient(0deg, var(--hsl) 50%, transparent 50%);
  background-repeat: repeat-y;
  background-size: 2px 10px;
  background-position: left top;
  animation: arrow-dance 5s infinite linear;

  @keyframes arrow-dance {
    0% {
      background-position: left bottom;
    }
    100% {
      background-position: left top;
    }
  }
  
  &::before {
    content: '';
    display: none;
    position: absolute;
    width: 50px;
    height: 50px;
    top: 0;
    left: 50%;
    background: var(--hsl);
    transform: translate(-50%, 0);
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
    animation: pulse 1s infinite;
    transition: all 0.05s ease;

    @keyframes pulse {
      0% {
        width: 50px;
        height: 50px;
      }
      50% {
        width: 60px;
        height: 60px;
      }
      100% {
        width: 50px;
        height: 50px;
      }
    }
  }

}

#angle,
#x,
#y {
  color: var(--hsl);
  position: absolute;
  font-family: 'Courier New', monospace;
  padding: 5px;
}

#angle {
  left: 0;
  bottom: 0;
}

#x {
  left: 0;
  top: 0;
}

#y {
  right: 0;
  top: 0;
}

#area {
  position: absolute;
  transition: all 0.05s ease;
  text-align: center;
  
  &::before {
    content: '';
    display: block;
    position: absolute;
    top: 0px;
    right: 0px;
    bottom: 0px;
    left: 0px;
    opacity: 50%;
    background: linear-gradient(90deg, var(--hsl) 50%, transparent 50%), linear-gradient(0deg, var(--hsl) 50%, transparent 50%), linear-gradient(90deg, var(--hsl) 50%, transparent 50%), linear-gradient(0deg, var(--hsl) 50%, transparent 50%);
    background-repeat: repeat-x,...

JavaScript

// on ready
$(function() {

  // constants
  const $zone = $('#zone');
  const $arrow = $('#arrow');
  const $area = $('#area');
  const $angle = $('#angle');
  const $hypotenuse = $('#hypotenuse');
  const $x = $('#x');
  const $y = $('#y');

  // let the root css selector
  let root = document.querySelector(':root');

  // current mouse position
  let currentMousePos = {
    x: -1,
    y: -1
  };

  // zone dimensions
  let currentWin = {
    x: $zone.width(),
    y: $zone.height()
  };

  // zone dimensions split
  let currentWinSplit = {
    x: currentWin.x / 2,
    y: currentWin.y / 2
  };

  // let our quater zone mouse position
  let quarterWin = {
    x: -1,
    y: -1
  }

  // calculate tangent angle
  function calcTangentAngle(x, y) {

    // return tangent angle degrees from x y
    return Math.atan2(y, x) * 180 / Math.PI;

  }

  // calculate quarter section coordinates
  function calcQuarterWin() {

    // if mouse is on right side of zone
    if (currentMousePos.x > currentWinSplit.x) {

      // set right side x quater zone mouse position
      // from center point
      quarterWin.x = currentMousePos.x - currentWinSplit.x;

      // else if mouse is on left side of zone
    } else {

      // set left side x quater zone mouse position 
      // from center point
      quarterWin.x = currentWinSplit.x - currentMousePos.x;

    }

    // if mouse is on bottom side of zone
    if (currentMousePos.y > currentWinSplit.y) {

      // set bottom side y quater zone mouse position
      // from center point
      quarterWin.y = currentMousePos.y - currentWinSplit.y;

    } else {

      // set bottom side y quater zone mouse position
      // from center point
      quarterWin.y = currentWinSplit.y - currentMousePos.y;

    }

  }

  // window on resize
  $(window).on('resize', function() {

    // update zone dimensions
    currentWin = {
      x: $zone.width(),
      y: $zone.height()
    };

    // update zone split dimensions
    currentWinSplit = {
  ...