123

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="container">
  <div class="base">
    <div class="svgClip">
      <svg viewBox="0 0 600 600">
        <rect x="0" y="0" />
        <defs>
          <filter id="shadow" x="-110%" y="-110%" height="335%" width="335%">
            <feOffset result="offOut" in="SourceGraphic" dx="0" dy="0" />
            <feGaussianBlur result="blurOut" in="offOut" stdDeviation="2" />
            <feBlend in="SourceGraphic" in2="blurOut" mode="normal" />          
          </filter>
          <filter id="ping-blur" x="-140%" y="-100%" height="300%" width="380%">
            <feOffset result="offOut" in="SourceGraphic" dx="0" dy="0" />
            <feGaussianBlur result="blurOut" in="offOut" stdDeviation="12" />
            <feBlend in="SourceGraphic" in2="blurOut" mode="normal" />          
          </filter>
          <radialGradient id="ping-bg" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
            <stop offset="50%" style="stop-color:#00ff80;
            stop-opacity:1" />
            <stop offset="100%" style="stop-color:#88ffc4;stop-opacity:0.9" />
          </radialGradient>
        </defs>
        
        <!--    Dotted lines    -->
        <circle cx="300" cy="300" r="75" filter="url(#shadow)" class="stroked five-metre" />
        <circle cx="300" cy="300" r="150" filter="url(#shadow)" class="stroked ten-metre" />
        <circle cx="300" cy="300" r="225" filter="url(#shadow)" class="stroked fifteen-metre"/>
        
        <!--    Vertical lines    -->
        <line x1="10" y1="215" x2="300" y2="300" class="directional-line side" filter="url(#shadow)" />
        <line x1="85" y1="85" x2="300" y2="300" class="directional-line forward" filter="url(#shadow)" />
        <line x1="215" y1="10" x2="300" y2="300" class="directional-line side" filter="url(#shadow)" />
        
        <!--    Top lines    -->
        <circle cx="300" cy="300" r="290" filter="url(#shadow)" />
        <circle cx="300" cy="300" r="280" filter="url(#shadow)" />
        
        <!--    Ping    -->
        <circle id="ping" class="ping" cx="200" cy="100" r="10" filter="url(#ping-blur)"/>
      </svg>
    </div>
    
    <!--   Edge lines   -->
    <svg class="containing-lines" viewBox="0 0 600 600">
      <line x1="385" y1="93" x2="385" y2="385" class="container-line" />
      <line x1="93" y1="385" x2="387" y2="385" class="container-line" />
    </svg>
    
    
    <svg class="directional-indicators" viewBox="0 0 600 600">
      <!--    Objective edge line    -->
      <rect id="objective" class="objective" x="0" y="0" rx="20" ry="20" filter="url(#shadow)" />
      
      <!--    Inner square to round corners    -->
      <rect class="objective-cover" x="20" y="20" />
      
      <!--    Off-tracker directional indicators   -->
      <path d="M230 450 Q 200 410 230 370" filter="url(#shadow)" id="left"/>
      <path d="M245 463 Q 300 490 355 463" filter="url(#shadow)" id="behind"/>
      <path d="M370 450 Q 400 410 370 370" filter="url(#shadow)" id="right"/>
    </svg>
  </div>
</div>
            
          
!
            
              *, *:before, *:after {
  box-sizing: border-box;
}

$radarWidth: 600px;

$bright-green: #00ff80;
$dull-green: #004b26;

body {
 background: url('https://jonnowitts.com/assets/static.gif') black;
}

span {
  color: white;
}

.container {
  margin: 0 auto;
  width: 800px;
}

.base {
  position: relative;
  width: $radarWidth;
  height: $radarWidth;
  margin: 0 auto;
}
 
.svgClip {
  position: absolute;
  left: 0px;
  top: 120px;
  /*
  To calculate with a Sass variable you need to use string interpolation - I.E. Replacing a variable/placeholder with the value - https://en.wikipedia.org/wiki/String_interpolation
  */
  clip: rect(0px, calc(#{$radarWidth}/2), calc(#{$radarWidth}/2), 0px);
  transform: rotate3d(0,0,1,45deg);
  
  rect {
    stroke-width: 30;
    fill: none;
    height: 100%;
    width: 100%;
  }
  
  circle:not(.ping) {
    stroke: #00ff80;
    stroke-width: 3;
    fill: none;
  }
  
  
  .ping {
    fill: url(#ping-bg);
    stroke: none;  
  }
}

svg {
  display: block;
  height: $radarWidth;
  width: $radarWidth;
  margin: 0 auto;
  
  circle.stroked {
    opacity: .75;
    &.five-metre {
      stroke-dasharray: 20;
      stroke-dashoffset: 16;
    }
    
    &.ten-metre {
      stroke-dasharray: 20;
    stroke-dashoffset: 21.2;
    }
    
    &.fifteen-metre {
      stroke-dasharray: 20;
      stroke-dashoffset: 6.5;
    }
  }
  
  .directional-line {
    stroke: #00ff80;
    stroke-width: 2;
    &.side {
      opacity: .5;
    }
    &.forward {
      opacity: .75;
    }
  }
}

.containing-lines {
  transform: rotate3d(0,0,1,45deg);
  .container-line {
    stroke: #6defa1;
    stroke-width: 5;
  }
}

.directional-indicators {
  position: absolute;
  top: 0;
  left: 0;
  path {
    stroke: $dull-green;
    stroke-width: 30;
    fill: none;
  }
}

.side-detect {
  stroke: #00ff80;
}

.objective {
  height: 100%;
  width: 100%;
  stroke-dasharray: 190 2220;
  stroke-dashoffset: -190;
  stroke-width: 40;
  stroke: $bright-green;
  fill: none;
}

.objective-cover {
  height: calc(100% - 40px);
  width: calc(100% - 40px);
  fill: none;
}

//  Just to make it slightly responsive
@media screen and (max-width: 600px) {  
  .base, svg {
    width: 300px;
    height: 300px;
  }
  
  .svgClip {
    top: 60px;
    clip: rect(0px, calc(#{300px}/2), calc(#{300px}/2), 0px);
  }
}
            
          
!
            
              var pageCoords,
    newPageCoords,
    offset = -175,
    offsetPlusVal = 11.8,
    ping = $('#ping'),
    pingCx = $('#ping').attr('cx'),
    pingCy = $('#ping').attr('cy'),
    moveVal = 8,
    
    // Initial colour in HSL format
    green = 'hsl(150,100%,15%)',
    incCol = 3,
    
    // Initial colour values split out
    eastColH = 150,
    eastColS = 100,
    eastColL = 15,
    behindColH = 150,
    behindColS = 100,
    behindColL = 15,
    westColH = 150,
    westColS = 100,
    westColL = 15,

    // Directional indicators
    eastInd = $('path#right'),
    behindInd = $('path#behind'),
    westInd = $('path#left');

eastInd.css('stroke', green);
behindInd.css('stroke', green);
westInd.css('stroke', green);

//alert(coords.heading);

$( "body" ).mousemove(function( event ) {
  var newPageCoords = event.pageX;
  
  //Detect the movement - this will move the objective marker
  if(pageCoords > newPageCoords) {
    //  Left
    offset += offsetPlusVal;
    $('.objective').css('stroke-dashoffset', offset);
    
    if(pingCx >= 120 && pingCy >= 65) {
      pingCx = parseInt(pingCx) + moveVal;
      pingCy = parseInt(pingCy) + moveVal;
      movePing(false);
    }
  }
  else {
    //  Right
    offset -= offsetPlusVal;
    $('.objective').css('stroke-dashoffset', offset);
    if(pingCx > 120 && pingCy > 66) {
      movePing(true);
    }
  }
  pageCoords = newPageCoords;
});

var angle = 180;

function movePing(clockwise) {
  var speed = 2,
      temp;
  // increase the angle of rotation
  
  if(clockwise) {
    angle += speed * Math.PI / 180;
  }
  else {
    angle -= speed * Math.PI / 180;
  }
  angle = angle.toFixed(2);
  angle = parseFloat(angle);
  
  //  Reset the ball at a complete loop
  if(angle >= 186.16){
    angle = 179.92;
  }
  else if(angle <= 173.44) {
    angle = 179.84;
  }
  

  // calculate the new ball.x / ball.y
  var newX = 300 + 180 * Math.cos(angle);
  var newY = 300 + 180 * Math.sin(angle);
  
  ping.attr('cx', newX + 'px');
  ping.attr('cy', newY + 'px');
  
  console.log(angle);
  
  var midPoint;
    
  if(angle >= 180.34 && angle <= 182.5 || 
     angle >= 174.08 && angle <= 176.08) {
    // East
    if(angle > 177){
      midPoint = 181.32;
    }
    else {
      midPoint = 175.08;
    }
    
    eastColL = directionalBrightness(angle, midPoint, eastColL, clockwise);
    eastInd.css('stroke', 
                'hsl(150, 100%, ' + eastColL + '%');
  }
  
  if(angle >= 182 && angle <= 184.32 ||
     angle >= 175.68 && angle <= 177.68) {
    // South
    if(angle > 180) {
      midPoint = 183.04;
    }
    else {
      midPoint = 176.68;
    }
    
    behindColL = directionalBrightness(angle, midPoint, behindColL, clockwise);
    behindInd.css('stroke',
                 'hsl(150, 100%, ' + behindColL + '%');
  }
  
  if(angle >= 183.66 && angle <= 185.62 ||
     angle >= 177.36 && angle <= 179.36) {
    // West
    if(angle > 180) {
      midPoint = 184.64;
    }
    else {
      midPoint = 178.36;  
    }
    westColL = directionalBrightness(angle, midPoint, westColL, clockwise);
    westInd.css('stroke',
                 'hsl(150, 100%, ' + westColL + '%');
  }
}

// This function returns the brightness of the directional indicator,
//  either getting lighter or darker.
// Midpoint is calculated by the two angles the ping can move between
function directionalBrightness(angle, midPoint, direction, clockwise) {
  if(angle <= midPoint) {
      switch(clockwise) {
        case true:
          if(direction < 65) {
            direction += incCol;
          }
          break;
        case false:
          if(direction > 15) {
            direction -= incCol;
          }
          break;
      }
    }
    else {
      switch(clockwise) {
        case false:
          if(direction < 65) {
            direction += incCol;
          }
          break;
        case true:
          if(direction > 15) {
            direction -= incCol;
          }
          break;
      }
    }
    return direction;
}


// Initial calculation of ball position
var newX = 300 + 207 * Math.cos(angle);
var newY = 300 + 155 * Math.sin(angle);

ping.attr('cx', newX + 'px');
ping.attr('cy', newY + 'px');
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console