clockface/clockface.go

35 lines
585 B
Go
Raw 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
)
type Point struct {
X float64
Y float64
}
func secondsInRadians(t time.Time) float64 {
return math.Pi / (30 / (float64(t.Second())))
}
2022-01-20 05:45:27 +00:00
func minutesInRadians(t time.Time) float64 {
return secondsInRadians(t)/60 + math.Pi/(30/(float64(t.Minute())))
}
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))
}