Skip to content

Commit 7fc2ffd

Browse files
committed
✨ (clockface): add build svg string
1 parent d929c0c commit 7fc2ffd

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed
File renamed without changes.

clockface/clockface_acceptance_test.go renamed to clockface_sample/clockface/clockface_acceptance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"testing"
55
"time"
66

7-
"github.com/leetcode-golang-classroom/learn-golang-with-tests/clockface"
7+
clockface "github.com/leetcode-golang-classroom/learn-golang-with-tests/clockface_sample/clockface"
88
)
99

1010
func TestSecondHandAtMidnight(t *testing.T) {
File renamed without changes.

clockface_sample/cmd/main.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"os"
7+
"time"
8+
9+
"github.com/leetcode-golang-classroom/learn-golang-with-tests/clockface_sample/clockface"
10+
)
11+
12+
func main() {
13+
t := time.Now()
14+
sh := clockface.SecondHand(t)
15+
io.WriteString(os.Stdout, svgStart)
16+
io.WriteString(os.Stdout, bezel)
17+
io.WriteString(os.Stdout, secondHandTag(sh))
18+
io.WriteString(os.Stdout, svgEnd)
19+
}
20+
21+
func secondHandTag(p clockface.Point) string {
22+
return fmt.Sprintf(`<line x1="150" y1="150" x2="%f" y2="%f" style="fill:none;stroke:#f00;stroke-width:3px;"/>`, p.X, p.Y)
23+
}
24+
25+
const svgStart = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
26+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
27+
<svg xmlns="http://www.w3.org/2000/svg"
28+
width="100%"
29+
height="100%"
30+
viewBox="0 0 300 300"
31+
version="2.0">`
32+
33+
const bezel = `<circle cx="150" cy="150" r="100" style="fill:#fff;stroke:#000;stroke-width:5px;"/>`
34+
35+
const svgEnd = `</svg>`

0 commit comments

Comments
 (0)