Files
meteor/examples/clock/clock.js
David Greenspan 45bd7f9e73 SVG clock demo
2013-12-11 14:59:55 -08:00

35 lines
940 B
JavaScript

if (Meteor.isClient) {
Meteor.startup(function () {
Meteor.setInterval(function () {
Session.set('time', new Date);
}, 1000);
});
Template.clock.hours = _.range(0, 12);
Template.clock.hourData = function () {
return { i: +this,
degrees: 30*this };
};
Template.clock.handData = function () {
var time = Session.get('time') || new Date;
return { hourDegrees: time.getHours() * 30,
minuteDegrees: time.getMinutes() * 6,
secondDegrees: time.getSeconds() * 6 };
};
Template.clock.radial = function (angleDegrees, startFraction, endFraction) {
var radius = 100;
var radians = (angleDegrees - 90) / 180 * Math.PI;
return {
x1: radius * startFraction * Math.cos(radians),
y1: radius * startFraction * Math.sin(radians),
x2: radius * endFraction * Math.cos(radians),
y2: radius * endFraction * Math.sin(radians)
};
};
}