Canvas Radar

Developer
Size
3,074 Kb
Views
74,888

How do I make an canvas radar?

What is a canvas radar? How do you make a canvas radar? This script and codes were developed by Jack Rugile on 11 August 2022, Thursday.

Canvas Radar Previews

Canvas Radar - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Canvas Radar</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ body { background: #111 url(/images/classy_fabric.png); overflow: hidden;
}
#bg { background: radial-gradient(hsla(0, 0%, 0%, 0), hsla(0, 0%, 0%, 1)); height: 100%; left: 0; position: absolute; width: 100%;
}
#radar { background: linear-gradient(#333, #111); box-shadow: 0 0 0 1px hsla(0, 0%, 0%, 0.5), inset 0 0 0 1px hsla(0, 0%, 100%, 0.15) ; padding: 14px; border-radius: 100%; display: block; left: 50%; position: absolute; top: 50%;
}
canvas { background: radial-gradient(#222, #111); border-radius: 100%; display: block;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <div id="bg"></div>
<div id="radar"></div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://rawgithub.com/soulwire/sketch.js/master/js/sketch.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Canvas Radar - Script Codes CSS Codes

body { background: #111 url(/images/classy_fabric.png); overflow: hidden;
}
#bg { background: radial-gradient(hsla(0, 0%, 0%, 0), hsla(0, 0%, 0%, 1)); height: 100%; left: 0; position: absolute; width: 100%;
}
#radar { background: linear-gradient(#333, #111); box-shadow: 0 0 0 1px hsla(0, 0%, 0%, 0.5), inset 0 0 0 1px hsla(0, 0%, 100%, 0.15) ; padding: 14px; border-radius: 100%; display: block; left: 50%; position: absolute; top: 50%;
}
canvas { background: radial-gradient(#222, #111); border-radius: 100%; display: block;
}

Canvas Radar - Script Codes JS Codes

var radar = document.getElementById( 'radar' ),
diameter = 220,
radius = diameter / 2,
padding = 14,
ctx = Sketch.create({ container: radar, fullscreen: false, width: diameter, height: diameter
}),
dToR = function( degrees ){ return degrees * (Math.PI / 180);
},
sweepAngle = 270,
sweepSize = 2,
sweepSpeed = 1.2,
rings = 4,
hueStart = 120,
hueEnd = 170,
hueDiff = Math.abs( hueEnd - hueStart ),
saturation = 50,
lightness = 40,
lineWidth = 2,
gradient = ctx.createLinearGradient( radius, 0, 0, 0 );
radar.style.marginLeft = radar.style.marginTop = ( -diameter / 2 ) - padding + 'px';
gradient.addColorStop( 0, 'hsla( ' + hueStart + ', ' + saturation + '%, ' + lightness + '%, 1 )' );
gradient.addColorStop( 1, 'hsla( ' + hueEnd + ', ' + saturation + '%, ' + lightness + '%, 0.1 )' );
var renderRings = function(){ var i; for( i = 0; i < rings; i++ ){ ctx.beginPath(); ctx.arc( radius, radius, ( ( radius - ( lineWidth / 2) ) / rings) * ( i + 1 ), 0, TWO_PI, false ); ctx.strokeStyle = 'hsla(' + ( hueEnd - ( i * ( hueDiff / rings ) ) ) + ', ' + saturation + '%, ' + lightness + '%, 0.1)'; ctx.lineWidth = lineWidth; ctx.stroke(); };
};
var renderGrid = function(){ ctx.beginPath(); ctx.moveTo( radius - lineWidth / 2, lineWidth ); ctx.lineTo( radius - lineWidth / 2, diameter - lineWidth ); ctx.moveTo( lineWidth, radius - lineWidth / 2 ); ctx.lineTo( diameter - lineWidth, radius - lineWidth / 2 ); ctx.strokeStyle = 'hsla( ' + ( ( hueStart + hueEnd ) / 2) + ', ' + saturation + '%, ' + lightness + '%, .03 )'; ctx.stroke();
};
var renderSweep = function(){ ctx.save(); ctx.translate( radius, radius ); ctx.rotate( dToR(sweepAngle) ); ctx.beginPath(); ctx.moveTo( 0, 0 ); ctx.arc( 0, 0, radius, dToR( -sweepSize ), dToR( sweepSize ), false ); ctx.closePath(); ctx.fillStyle = gradient; ctx.fill(); ctx.restore();
};
var renderScanLines = function(){ var i; var j; ctx.beginPath(); for( i = 0; i < diameter; i += 2 ){ ctx.moveTo( 0, i + .5 ); ctx.lineTo( diameter, i + .5); }; ctx.lineWidth = 1; ctx.strokeStyle = 'hsla( 0, 0%, 0%, .02 )'; ctx.globalCompositeOperation = 'source-over'; ctx.stroke();
};
ctx.clear = function(){ ctx.globalCompositeOperation = 'destination-out'; ctx.fillStyle = 'hsla( 0, 0%, 0%, 0.1 )'; ctx.fillRect( 0, 0, diameter, diameter );
};
ctx.update = function(){ sweepAngle += sweepSpeed;
};
ctx.draw = function(){ ctx.globalCompositeOperation = 'lighter'; renderRings(); renderGrid(); renderSweep(); renderScanLines();
};
Canvas Radar - Script Codes
Canvas Radar - Script Codes
Home Page Home
Developer Jack Rugile
Username jackrugile
Uploaded August 11, 2022
Rating 4
Size 3,074 Kb
Views 74,888
Do you need developer help for Canvas Radar?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Jack Rugile (jackrugile) Script Codes
Create amazing marketing copy with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!