35 lines
678 B
Go
35 lines
678 B
Go
package main
|
|
|
|
import (
|
|
"math"
|
|
"time"
|
|
)
|
|
|
|
const secondHandLength = 90
|
|
const clockCentreX = 150
|
|
const clockCentreY = 150
|
|
|
|
type Point struct {
|
|
X float64
|
|
Y float64
|
|
}
|
|
|
|
func SecondHand(t time.Time) Point {
|
|
p := secondHandPoint(t)
|
|
p = Point{p.X * secondHandLength, p.Y * secondHandLength} //scale
|
|
p = Point{p.X, -p.Y} //flip
|
|
p = Point{p.X + clockCentreX, p.Y + clockCentreY} //translate
|
|
return p
|
|
}
|
|
|
|
func secondsInRadians(t time.Time) float64 {
|
|
return math.Pi / (30 / (float64(t.Second())))
|
|
}
|
|
|
|
func secondHandPoint(t time.Time) Point {
|
|
angle := secondsInRadians(t)
|
|
x := math.Sin(angle)
|
|
y := math.Cos(angle)
|
|
return Point{x, y}
|
|
}
|