let counter = 0, canvas = document.getElementsByTagName('canvas')[0], context = canvas.getContext('2d')
function renderFrame() {
// Clear background
context.fillStyle = '#333'
context.fillRect(0, 0, canvas.width, canvas.height)
// Draw numbers
context.fillStyle = '#f0f'
renderNumber(9876543210, /* x */458, /* y */100, /* width */30, /* height */ 60, /* thickness */ 6, /* spacing */ 5)
renderNumber(counter++ , /* x */500, /* y */240, /* width */80, /* height */160, /* thickness */16, /* spacing */12)
// Continue animation
requestAnimationFrame(renderFrame)
}
/*
* Use a cascading switch statement to exploit the fact that some numbers can be drawn with a combination of other numbers.
*/
function renderNumber(num, x, y, w, h, t, spacing) {
for (; num; num /= 10, num >>>= 0, x -= w + spacing) {
let digit = num % 10;
switch (digit) {
case 8:
context.fillRect(x , y + h * .5 + t * .5, t , h * .5 - t * 1.5) // Bottom-left
case 9:
context.fillRect(x + t , y , w - t * 2, t ) // Top
context.fillRect(x + t , y + h - t , w - t * 2, t ) // Bottom
case 3:
if (digit !== 4)
context.fillRect(x + t , y , w - t * 2, t ) // Top
context.fillRect(x + w - t, y + t , t , h * .5 - t * 1.5) // Top-right
context.fillRect(x + t , y + h * .5 - t * .5, w - t * 2, t ) // Middle
context.fillRect(x + t , y + h - t , w - t * 2, t ) // Bottom
context.fillRect(x + w - t, y + h * .5 + t * .5, t , h * .5 - t * 1.5) // Bottom-right
case 4:
if (digit !== 3)
context.fillRect(x , y + t , t , h * .5 - t * 1.5) // Top-left
context.fillRect(x + w - t, y + t , t , h * .5 - t * 1.5) // Top-right
context.fillRect(x + t , y + h...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.