clockface: refactor magic numbers
This commit is contained in:
parent
6837cd9fc1
commit
ef646bf98e
@ -21,6 +21,15 @@ const (
|
||||
clockCentreY = 150
|
||||
)
|
||||
|
||||
const (
|
||||
secondsInHalfClock = 30
|
||||
secondsInClock = 2 * secondsInHalfClock
|
||||
minutesInHalfClock = 30
|
||||
minutesInClock = 2 * minutesInHalfClock
|
||||
hoursInHalfClock = 6
|
||||
hoursInClock = 2 * hoursInHalfClock
|
||||
)
|
||||
|
||||
const svgStart = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg xmlns="http://www.w3.org/2000/svg"
|
||||
@ -73,7 +82,7 @@ func makeHand(w io.Writer, length float64, p Point) {
|
||||
}
|
||||
|
||||
func hoursInRadians(t time.Time) float64 {
|
||||
return (minutesInRadians(t) / 12) + math.Pi/(6/float64(t.Hour()%12))
|
||||
return (minutesInRadians(t) / hoursInClock) + math.Pi/(hoursInHalfClock/float64(t.Hour()%hoursInClock))
|
||||
}
|
||||
|
||||
func hourHandPoint(t time.Time) Point {
|
||||
@ -81,7 +90,7 @@ func hourHandPoint(t time.Time) Point {
|
||||
}
|
||||
|
||||
func minutesInRadians(t time.Time) float64 {
|
||||
return (secondsInRadians(t) / 60) + math.Pi/(30/float64(t.Minute()))
|
||||
return (secondsInRadians(t) / minutesInClock) + math.Pi/(minutesInHalfClock/float64(t.Minute()))
|
||||
}
|
||||
|
||||
func minuteHandPoint(t time.Time) Point {
|
||||
@ -89,7 +98,7 @@ func minuteHandPoint(t time.Time) Point {
|
||||
}
|
||||
|
||||
func secondsInRadians(t time.Time) float64 {
|
||||
return math.Pi / (30 / float64(t.Second()))
|
||||
return math.Pi / (secondsInHalfClock / float64(t.Second()))
|
||||
}
|
||||
|
||||
func secondHandPoint(t time.Time) Point {
|
||||
|
Loading…
Reference in New Issue
Block a user