-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriangles.go
71 lines (63 loc) · 976 Bytes
/
triangles.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package svgr
import (
"fmt"
"math/rand"
"time"
)
type triangle [3]*point
func (m *Mosaic) Triangles(rnd int) string {
src := rand.New(rand.NewSource(time.Now().UnixNano()))
return m.render(func() string {
var tri triangle
x := m.current.X * shapeSize
y := m.current.Y * shapeSize
if m.current.X%2 == 0 {
// Draw down-pointing triangle
tri = triangle{
&point{
x - 4,
y,
},
&point{
x + 16,
y,
},
&point{
x + 6,
y + 10,
},
}
} else {
// Draw up-pointing triangle
tri = triangle{
&point{
x - 4,
y + 10,
},
&point{
x + 16,
y + 10,
},
&point{
x + 6,
y,
},
}
}
if rnd > 0 {
for _, pt := range tri {
pt.randomize(*src, rnd)
}
}
return fmt.Sprintf(
"<polygon points=\"%d,%d %d,%d %d,%d\" fill=\"%s\"/>",
tri[0].x,
tri[0].y,
tri[1].x,
tri[1].y,
tri[2].x,
tri[2].y,
m.colorAtCurrent(),
)
})
}