From c6ef156d885af3035469e74a3b1f272bed2a083e Mon Sep 17 00:00:00 2001 From: vinchent Date: Mon, 23 Sep 2024 22:18:46 +0200 Subject: [PATCH] clockface: refactor --- clockface/clockface.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/clockface/clockface.go b/clockface/clockface.go index f607d67..71366aa 100644 --- a/clockface/clockface.go +++ b/clockface/clockface.go @@ -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, - ``, - 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, ``,