-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsquares.go
More file actions
47 lines (39 loc) · 793 Bytes
/
squares.go
File metadata and controls
47 lines (39 loc) · 793 Bytes
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
package svgr
import (
"fmt"
"math/rand"
"time"
)
type square [4]*point
// Render squares
// NOTE: <polygon> is more slightly terser than <rect> ¯\_(ツ)_/¯
func (m *Mosaic) Squares(rnd int) string {
src := rand.New(rand.NewSource(time.Now().UnixNano()))
return m.render(func() string {
x := m.current.X * shapeSize
y := m.current.Y * shapeSize
sq := square{
&point{x, y},
&point{x + shapeSize, y},
&point{x + shapeSize, y + shapeSize},
&point{x, y + shapeSize},
}
if rnd > 0 {
for _, pt := range sq {
pt.randomize(*src, rnd)
}
}
return fmt.Sprintf(
"<polygon points=\"%d,%d %d,%d %d,%d %d,%d\" fill=\"%s\"/>",
sq[0].x,
sq[0].y,
sq[1].x,
sq[1].y,
sq[2].x,
sq[2].y,
sq[3].x,
sq[3].y,
m.colorAtCurrent(),
)
})
}