cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              
        
    <body>
        <!--[if lt IE 8]>
            <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->
		<canvas id="canvas"></canvas><br />
		<span>by <a href="https://ganeshmkumar.github.io" target="_blank">GaNeShKuMaRm</a> ☺</span>
    </body>
</html>
            
          
!
            
              body {
	background-color: #202833;
	text-align: center;
	color: #fafafa;
}

span {
	font-family: 'Lobster';
}

a {
	color: #fafafa;
	transition: linear 0.3s;
}

a:hover {
	opacity: 0.8;
}
a, a:hover {
	text-decoration: none;
}


            
          
!
            
              var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var min, sec, hr, ms, amOrPm = 'AM';
var radH, radM, radS;
const threePIByTwo = (3 * Math.PI) / 2;
function init()
{
	canvas.width = document.documentElement.clientWidth - 35;
	canvas.height = document.documentElement.clientHeight - 45;
	window.requestAnimationFrame(draw);	
}

function draw(now)
{
	var centerX = canvas.width / 2,
		centerY = canvas.height / 2,
		date = new Date();

	hr = date.getHours();
	min = date.getMinutes();
	sec = date.getSeconds();
	ms = date.getMilliseconds();
	if(hr > 12)
	{
		amOrPm = 'PM';
    hr -= 12;
	}
	radH = 0.000008333 * ( ( hr * 60 * 60 * 1000 ) + ( min * 60 * 1000 ) + ( sec * 1000 ) + ms );
	radM = 0.0001 * ( ( min * 60 * 1000 ) + ( sec * 1000 ) + ms );
	radS = 0.006 * ( ( sec * 1000 ) + ms );

	drawRect(0, 0, canvas.width, canvas.height, '#202833');
	drawCircle(centerX, centerY, 220, 0, Math.PI * 2, false, '#546E7A', 'stroke', 30); //secondgrey
	drawCircle(centerX, centerY, 220, threePIByTwo, rad(radS) + threePIByTwo, false, '#DC543E', 'stroke', 30); //second
	drawCircle(centerX, centerY, 180, 0, Math.PI * 2, false, '#455A64', 'stroke', 50); //minutegrey
	drawCircle(centerX, centerY, 180, threePIByTwo, rad(radM) + threePIByTwo, false, '#FEB737', 'stroke', 50); //minute
	drawCircle(centerX, centerY, 110, 0, Math.PI * 2 , false, '#37474F', 'stroke', 90); //hourgrey
	drawCircle(centerX, centerY, 110, threePIByTwo, rad(radH) + threePIByTwo, false, '#27AE61', 'stroke', 90); //hour
	drawCircle(centerX, centerY, 95, 0, Math.PI * 2, false, '#263238', 'fill', '50'); //inner
	drawText(`${hr.toString().length == 1?'0'+hr:hr}:${min.toString().length == 1?'0'+min:min}:${sec.toString().length == 1?'0'+sec:sec}`, canvas.width / 2 - 63, canvas.height / 2 + 15, '#ffffff', '40px');
	drawText(amOrPm, canvas.width / 2 - 15, canvas.height / 2 + 50, '#ffffff', '25px');
	window.requestAnimationFrame(draw);	
}

init();

function rad(deg){
	return  (Math.PI / 180) * deg;
}

function drawText(text, x, y, color, size) {
	ctx.font = `${size} "Passion One"`;
	ctx.fillStyle = color;
	ctx.fillText(text, x, y);
}

function drawRect(x, y, width, height, color) {
	ctx.fillStyle = color;
	ctx.fillRect(x, y, width, height);
}

function drawArc(x, y, radius, start, end, clockwise)
{
	ctx.beginPath();
	ctx.arc(x, y, radius, start, end, clockwise);
}

function drawCircle(x, y, radius, start, end, clockwise, color, type, thickness) {
	if(type == 'fill')
	{
		ctx.fillStyle = color;
		drawArc(x, y, radius, start, end, clockwise)
		ctx.fill();
	}
	else if(type == 'stroke')
	{
		ctx.strokeStyle = color;
		ctx.lineWidth = thickness;
		drawArc(x, y, radius, start, end, clockwise)
		ctx.stroke();
	}
}
            
          
!
999px
Loading ..................

Console