clockface: refactor
This commit is contained in:
parent
a4531bde4c
commit
c6ef156d88
@ -43,23 +43,19 @@ func SVGWriter(w io.Writer, t time.Time) {
|
||||
// SecondHand is the unit vector of the second hand of an analogue clock at the time `t` represented as a Point
|
||||
func secondHand(w io.Writer, t time.Time) {
|
||||
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
|
||||
fmt.Fprintf(
|
||||
w,
|
||||
`<line x1="150" y1="150" x2="%f" y2="%f" style="fill:none;stroke:#f00;stroke-width:3px;"/>`,
|
||||
p.X,
|
||||
p.Y,
|
||||
)
|
||||
makeHand(w, secondHandLength, p)
|
||||
}
|
||||
|
||||
// MinuteHand is the unit vector of the minute hand of an analogue clock at the time `t` represented as a Point
|
||||
func minuteHand(w io.Writer, t time.Time) {
|
||||
p := minuteHandPoint(t)
|
||||
p = Point{p.X * minuteHandLength, p.Y * minuteHandLength} // scale
|
||||
p = Point{p.X, -p.Y} // flip
|
||||
p = Point{p.X + clockCentreX, p.Y + clockCentreY} // translate
|
||||
makeHand(w, minuteHandLength, p)
|
||||
}
|
||||
|
||||
func makeHand(w io.Writer, length float64, p Point) {
|
||||
p = Point{p.X * length, p.Y * length} // scale
|
||||
p = Point{p.X, -p.Y} // flip
|
||||
p = Point{p.X + clockCentreX, p.Y + clockCentreY} // translate
|
||||
fmt.Fprintf(
|
||||
w,
|
||||
`<line x1="150" y1="150" x2="%f" y2="%f" style="fill:none;stroke:#f00;stroke-width:3px;"/>`,
|
||||
|
Loading…
Reference in New Issue
Block a user