clockface: add main func

This commit is contained in:
vinchent 2024-09-23 16:57:24 +02:00
parent c9c9b9bf7b
commit 423c9e9567
2 changed files with 37 additions and 3 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
clock.svg
gobytest

38
main.go
View File

@ -1,14 +1,46 @@
package main
import (
"gobytest/countdown"
"fmt"
"gobytest/clockface"
"io"
"os"
"time"
)
func main() {
// greet.Greet(os.Stdout, "Elodie")
sleeper := countdown.NewConfigurableSleeper(1*time.Second, time.Sleep)
// sleeper := countdown.NewConfigurableSleeper(1*time.Second, time.Sleep)
countdown.Countdown(os.Stdout, sleeper)
// countdown
// countdown.Countdown(os.Stdout, sleeper)
// clockface
t := time.Now()
sh := clockface.SecondHand(t)
io.WriteString(os.Stdout, svgStart)
io.WriteString(os.Stdout, bezel)
io.WriteString(os.Stdout, secondHandTag(sh))
io.WriteString(os.Stdout, svgEnd)
}
func secondHandTag(p clockface.Point) string {
return fmt.Sprintf(
`<line x1="150" y1="150" x2="%f" y2="%f" style="fill:none;stroke:#f00;stroke-width:3px;"/>`,
p.X,
p.Y,
)
}
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"
width="100%"
height="100%"
viewBox="0 0 300 300"
version="2.0">`
const bezel = `<circle cx="150" cy="150" r="100" style="fill:#fff;stroke:#000;stroke-width:5px;"/>`
const svgEnd = `</svg>`