Skip to content

Instantly share code, notes, and snippets.

@chrisciampoli
Created February 21, 2015 06:58
Show Gist options
  • Save chrisciampoli/c8e365469e5738910bf4 to your computer and use it in GitHub Desktop.
Save chrisciampoli/c8e365469e5738910bf4 to your computer and use it in GitHub Desktop.
Awesome Clock
function AngleCalc() {
function fromTime(min, hour){
var minPercent = minutesToPercent(min),
hrPercent = hoursToPercent(hour, minPercent),
minDegree = percentageToDegree(minPercent),
hrDegree = percentageToDegree(hrPercent),
smallAngle = smAngle(minDegree, hrDegree),
largeAngle = lgAngle(minDegree, hrDegree);
return {
lg:largeAngle,
sm:smallAngle
}
}
//private
function percentageToDegree(percent) {
return 360 * (percent / 100);
}
function minutesToPercent(min) {
return (min * 100) / 60;
}
function hoursToPercent(hour, minPercent) {
var hourMod = hour%12,
degreeInHr = 100 /12,
hourPercent = (hour * 100) / 12;
return hourPercent + (degreeInHr * (minPercent / 100)) % 100;
}
function smAngle(minDegree , hrDegree){
return Math.abs((360 - minDegree) - hrDegree);
}
function lgAngle(minDegree, hrDegree) {
return Math.abs(360 - smAngle(minDegree, hrDegree));
}
return {
fromTime: fromTime
}
}
var calc = new AngleCalc
calc.fromTime(7, 10);
console.log(calc.fromTime(7, 10));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment