clockface: refactor
This commit is contained in:
parent
a4531bde4c
commit
c6ef156d88
@ -43,21 +43,17 @@ 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
|
// 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) {
|
func secondHand(w io.Writer, t time.Time) {
|
||||||
p := secondHandPoint(t)
|
p := secondHandPoint(t)
|
||||||
p = Point{p.X * secondHandLength, p.Y * secondHandLength} // scale
|
makeHand(w, secondHandLength, p)
|
||||||
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,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MinuteHand is the unit vector of the minute hand of an analogue clock at the time `t` represented as a Point
|
// 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) {
|
func minuteHand(w io.Writer, t time.Time) {
|
||||||
p := minuteHandPoint(t)
|
p := minuteHandPoint(t)
|
||||||
p = Point{p.X * minuteHandLength, p.Y * minuteHandLength} // scale
|
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, -p.Y} // flip
|
||||||
p = Point{p.X + clockCentreX, p.Y + clockCentreY} // translate
|
p = Point{p.X + clockCentreX, p.Y + clockCentreY} // translate
|
||||||
fmt.Fprintf(
|
fmt.Fprintf(
|
||||||
|
Loading…
Reference in New Issue
Block a user