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(); });
});
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 |
Enchant.js sample | 3,131 Kb |
Three.js ver.2 animation | 3,114 Kb |
Masonry | 5,005 Kb |
Canvas circle gauge | 3,773 Kb |
AngularJS - first step - | 3,009 Kb |
ClickPanel | 3,068 Kb |
Simple genetic algorithm | 10,179 Kb |
Css action sideBar | 3,928 Kb |
Shuffle text word separator | 3,208 Kb |
Glitch test | 4,246 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 |
Animated Slide Hamburger Mobile Menu | BJack | 2,247 Kb |
Pure CSS Dial | Lukewatts | 3,018 Kb |
Background Images | Jooonebug | 2,100 Kb |
Prototype Responsive Homepage | Heyitsolivia | 7,677 Kb |
SCSS Simple Animated Drop-In | Danwarfel | 2,175 Kb |
P5.js data visualization | Enginarslan | 2,233 Kb |
Polo, the flying squirrel | Agbales | 2,445 Kb |
Blog demo to use given styling | Andygirl | 2,412 Kb |
Count up | Alanshortis | 2,391 Kb |
A simple log in form made with css | Mayurelbhar | 2,160 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!