UNPKG

soma.js

Version:

soma.js is a javascript framework created to build scalable and maintainable applications.

82 lines (74 loc) 2.74 kB
// Generated by CoffeeScript 1.6.2 (function() { (function(clock) { "use strict"; return clock.PolarView = (function() { function PolarView(target) { var calculateColor, canvas, context, height, tick, width, writeTime; this.element = target; width = 300; height = 300; canvas = document.createElement('canvas'); context = canvas.getContext('2d'); canvas.width = width; canvas.height = height; target.appendChild(canvas); tick = function(time) { var day, dayPer, dow, dowPer, hr, hrPer, milliSec, min, minPer, month, monthPer, sec, secPer; context.save(); context.clearRect(0, 0, width, height); context.translate(width * 0.5, width * 0.5); context.rotate(-Math.PI / 2); context.lineWidth = 18; milliSec = time.milliseconds; sec = milliSec / 1000 + time.seconds; min = sec / 60 + time.minutes; hr = min / 60 + time.hours; dow = time.day; day = time.date; month = time.month; secPer = sec / 60; minPer = min / 60; hrPer = hr / 24; dowPer = dow / 7; monthPer = month / 12; dayPer = 0; if (month === 2) { dayPer = day / 29; } else if (month === 1 || month === 3 || month === 5 || month === 7 || month === 8 || month === 10 || month === 12) { dayPer = day / 31; } else { dayPer = day / 30; } writeTime(context, 40, monthPer); writeTime(context, 60, dayPer); writeTime(context, 80, dowPer); writeTime(context, 100, hrPer); writeTime(context, 120, minPer); writeTime(context, 140, secPer); return context.restore(); }; writeTime = function(context, radius, per) { context.save(); context.strokeStyle = calculateColor(per); context.beginPath(); context.arc(0, 0, radius, 0, per * (Math.PI * 2), false); context.stroke(); return context.restore(); }; calculateColor = function(per) { var blue, brightness, green, red; brightness = 255; red = 0; blue = per * brightness; green = brightness - blue; return 'rgba(' + Math.round(red) + ',' + Math.round(green) + ',' + Math.round(blue) + ',1)'; }; this.update = tick.bind(this); } PolarView.prototype.dispose = function() { return this.element.removeChild(this.element.firstChild); }; return PolarView; })(); })(window.clock = window.clock || {}); }).call(this);