clockface/clockface.go

52 lines
1.1 KiB
Go
Raw Permalink Normal View History

2022-01-20 04:26:08 +00:00
package clockface
2022-01-20 04:29:46 +00:00
import (
"math"
2022-01-20 04:31:19 +00:00
"time"
2022-01-20 04:29:46 +00:00
)
2022-01-20 06:07:29 +00:00
const (
secondsInHalfClock = 30
secondsInClock = 2 * secondsInHalfClock
minutesInHalfClock = 30
minutesInClock = 2 * minutesInHalfClock
hoursInHalfClock = 6
hoursInClock = 2 * hoursInHalfClock
)
2022-01-20 04:29:46 +00:00
type Point struct {
X float64
Y float64
}
func secondsInRadians(t time.Time) float64 {
2022-01-20 06:07:29 +00:00
return math.Pi / (secondsInHalfClock / (float64(t.Second())))
2022-01-20 04:29:46 +00:00
}
2022-01-20 05:45:27 +00:00
func minutesInRadians(t time.Time) float64 {
2022-01-20 06:07:29 +00:00
return secondsInRadians(t)/minutesInClock + math.Pi/(minutesInHalfClock/(float64(t.Minute())))
}
func hoursInRadians(t time.Time) float64 {
return (minutesInRadians(t) / hoursInClock) + (math.Pi / (hoursInHalfClock / float64(t.Hour()%hoursInClock)))
2022-01-20 05:45:27 +00:00
}
func angleToPoint(angle float64) Point {
2022-01-20 04:29:46 +00:00
x := math.Sin(angle)
y := math.Cos(angle)
2022-01-20 05:45:27 +00:00
2022-01-20 04:29:46 +00:00
return Point{x, y}
}
2022-01-20 05:45:27 +00:00
func secondHandPoint(t time.Time) Point {
return angleToPoint(secondsInRadians(t))
}
func minuteHandPoint(t time.Time) Point {
return angleToPoint(minutesInRadians(t))
}
2022-01-20 06:07:29 +00:00
func hourHandPoint(t time.Time) Point {
return angleToPoint(hoursInRadians(t))
}