-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
avatar_pixel.go
34 lines (28 loc) · 904 Bytes
/
avatar_pixel.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
package plavatar
import (
svg "github.com/ajstarks/svgo"
"github.com/jonasdoesthings/plavatar/v3/utils"
"math/rand"
)
// Pixels
// TODO:
// Currently this always outputs a [ShapeCircle] in PNG output mode.
// oksvg does not support clippaths at the moment, so the whole square gets rasterized
// see: https://github.com/srwiley/oksvg/issues/10
func (generator *Generator) Pixels(canvas *svg.SVG, rng *rand.Rand, rngSeed int64, options *Options) {
pixels := CanvasSize / 8
if options.OutputShape == ShapeCircle {
canvas.Def()
canvas.ClipPath("id=\"clip\"")
canvas.Circle(0, 0, CanvasSize/2)
canvas.ClipEnd()
canvas.DefEnd()
}
canvas.Group("clip-path=\"url(#clip)\"")
for x := -CanvasSize / 2; x < CanvasSize/2; x += pixels {
for y := -CanvasSize / 2; y < CanvasSize/2; y += pixels {
canvas.Rect(x, y, pixels, pixels, "fill:"+utils.RandomColorHex(rng))
}
}
canvas.Gend()
}