-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_test.go
69 lines (62 loc) · 1.66 KB
/
example_test.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
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ivg_test
import (
"image"
"image/draw"
"log"
"os"
"path/filepath"
"github.com/reactivego/ivg/decode"
"github.com/reactivego/ivg/raster/vec"
"github.com/reactivego/ivg/render"
)
func Example() {
ivgData, err := os.ReadFile(filepath.FromSlash("testdata/action-info.lores.ivg"))
if err != nil {
log.Fatal(err)
}
const width = 24
dst := image.NewAlpha(image.Rect(0, 0, width, width))
var z render.Renderer
z.SetRasterizer(&vec.Rasterizer{Dst: dst, DrawOp: draw.Src}, dst.Bounds())
if err := decode.Decode(&z, ivgData); err != nil {
log.Fatal(err)
}
const asciiArt = ".++8"
buf := make([]byte, 0, width*(width+1))
for y := 0; y < width; y++ {
for x := 0; x < width; x++ {
a := dst.AlphaAt(x, y).A
buf = append(buf, asciiArt[a>>6])
}
buf = append(buf, '\n')
}
os.Stdout.Write(buf)
// Output:
// ........................
// ........................
// ........++8888++........
// ......+8888888888+......
// .....+888888888888+.....
// ....+88888888888888+....
// ...+8888888888888888+...
// ...88888888..88888888...
// ..+88888888..88888888+..
// ..+888888888888888888+..
// ..88888888888888888888..
// ..888888888..888888888..
// ..888888888..888888888..
// ..888888888..888888888..
// ..+88888888..88888888+..
// ..+88888888..88888888+..
// ...88888888..88888888...
// ...+8888888888888888+...
// ....+88888888888888+....
// .....+888888888888+.....
// ......+8888888888+......
// ........++8888++........
// ........................
// ........................
}