Canvas circle gauge
How do I make an canvas circle gauge?
What is a canvas circle gauge? How do you make a canvas circle gauge? This script and codes were developed by Uriuriuriu on 10 January 2023, Tuesday.
Canvas circle gauge - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>canvas circle gauge</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <p id="restart_text"> click restart
</p>
<div id="numberbox_container"></div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.1/underscore-min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Canvas circle gauge - Script Codes CSS Codes
@import url(https://fonts.googleapis.com/css?family=Economica);
body { background-color: #131315; cursor: pointer;
}
#restart_text { position: absolute; top: 50%; left: 50%; font-family: 'Economica', sans-serif; font-size: 30px; color: #ff0000; -webkit-animation: blink 1s ease-in-out infinite alternate; -moz-animation: blink 1s ease-in-out infinite alternate; animation: blink 1s ease-in-out infinite alternate;
}
@-webkit-keyframes blink { 0% { opacity: 0; } 100% { opacity: 1; }
}
.circle { position: relative; display: inline-block; width: 80px; height: 80px; border: 1px dotted #0c0c0d;
}
.circle_num { position: absolute; top: 50%; left: 0; margin-top: -0.5em; width: 100%; text-align: center; color: white; font-size: 14px; font-family: 'Economica', sans-serif;
}
Canvas circle gauge - Script Codes JS Codes
$(function(){ var LIGHT_COLOR = '#7da398'; var FPS = 30; var ANIME_DURATION = .9; // sec var setCanvas =function(num, appendContainer) { var ele = $('<div class="circle" data-user-par='+ num +'></div>').appendTo(appendContainer); var fixSize = $(ele).width(); var canvas = document.createElement("canvas"); canvas.width = fixSize; canvas.height = fixSize; console.log(fixSize); $(ele).html(canvas); $(ele).append('<div class="circle_num"></div>'); } var drawCircle =function(ele, par, progress) { // set number var numWrapper = $(ele).find("div")[0]; $(numWrapper).text(Math.round(par * 100)); // get canvas var canvas = $(ele).find("canvas")[0]; var fixSize = $(ele).width(); var ctx = canvas.getContext('2d'); // clear ctx.clearRect(0, 0, fixSize, fixSize); // draw ctx.globalAlpha = 1; // start flash if(progress < .06 || (.15 <= progress && progress < .20)){ ctx.globalAlpha = 0.25; ctx.fillStyle = LIGHT_COLOR; ctx.fillRect(fixSize*0.1, fixSize*0.1, fixSize*0.8, fixSize*0.8); } var radStart = -90 * Math.PI / 180; var radEnd = (-90 + (par*360)) * Math.PI / 180; ctx.lineWidth = 1.5; ctx.strokeStyle = LIGHT_COLOR; ctx.beginPath(); ctx.arc(fixSize / 2, // startX fixSize / 2, // startY fixSize / 3, // radius radStart, radEnd, false); ctx.stroke(); // decoration lines ctx.lineWidth = 3; ctx.beginPath(); ctx.moveTo(fixSize-4, fixSize); ctx.lineTo(fixSize, fixSize); ctx.stroke(); ctx.lineWidth = 0.2; ctx.strokeStyle = LIGHT_COLOR; ctx.beginPath(); ctx.moveTo(0, 0); ctx.lineTo(fixSize, fixSize); ctx.stroke(); }; // timer var start = function(){ var milSec = 1000 / FPS; var limitFlame = ANIME_DURATION * FPS; _.each($('.circle'), function(ele){ var drawStart = function(){ var j = 0; var maxNum = ele.dataset.userPar; var loop = function(){ j++; var nowNum = maxNum * (j / limitFlame); drawCircle(ele, nowNum, j / limitFlame); if(limitFlame <= j)return; // end clearTimeout(timer); var timer = setTimeout(loop, milSec); } loop(); } // set random setTimeout(drawStart, Math.random() *2000); }); } // *start! // canvas setting var numberAr = [0.24, 0.42, 0.94, 0.3, 0.2, 0.4, 0.9, 0.3, 0.2, 0.4, 0.9, 0.3, 0.2, 0.4, 0.9, 0.3, 0.11, 0.2, 0.4, 0.9, 0.3, 0.1, 0.2, 0.4, 0.9, 0.3, 0.1, 0.2, 0.46, 0.91, 0.3, 0, 0.7, 0.2, 0.4, 0.9, 0.3, 0.1, 0.2, 0.4, 0.9, 0.3, 0.1, 0.2, 0.4, 0.9, 0.3, 0, 0.7, 0.2, 0.4, 0.9, 0.3, 0.1, 0.2, 0.4, 0.9, 0.3, 0.1, 0.2, 0.4, 0.9, 0.3, 0, 0.7]; _.each(numberAr, function(num){ setCanvas(num, $("#numberbox_container")); }); start(); // mouse event $('html').mousemove(function(e){ $('#restart_text').css({top:e.pageY-25, left:e.pageX-50}); }); $("body").click(function(){ start(); });
});
![Canvas circle gauge - Script Codes](http://shots.codepen.io/uriuriuriu/pen/iuAma-512.jpg)
Developer | Uriuriuriu |
Username | uriuriuriu |
Uploaded | January 10, 2023 |
Rating | 3 |
Size | 3,773 Kb |
Views | 6,072 |
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!
Name | Size |
AngularJS - first step - | 3,009 Kb |
Glitch test | 4,246 Kb |
Canvas Gaussian Blur | 3,439 Kb |
Shuffle text word separator | 3,208 Kb |
SANGETUKI separator | 11,128 Kb |
TV effect | 3,293 Kb |
Three.js ver.2 animation | 3,114 Kb |
Glitch Video | 3,178 Kb |
Three.js earth | 3,423 Kb |
Masonry | 5,005 Kb |
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!
Name | Username | Size |
SVG hamburger menu button | Elifitch | 2,602 Kb |
Jquery 2d character movement | Drewtadams | 4,291 Kb |
Image grid with captions | Mchernin34 | 2,222 Kb |
Swiftype Lower Third | Zumwalt | 4,796 Kb |
Michelle, submit your photography to Unsplash. | Zaneriley | 3,368 Kb |
Canvas snow | Win7killer | 2,572 Kb |
Animated bar chart | CreativePunch | 3,124 Kb |
Birthday Party Starter | Aussieyang | 1,629 Kb |
TweenMax transformOrigin Bubble | Nicolund | 2,209 Kb |
Materializecss input form | Jasonchan | 1,443 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!