Debian Codegraph @

shiny/iconvg/example_test.go

raw symbols SCIP
1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package iconvg_test
6
7 import (
8 "image"
9 "image/draw"
10 "log"
11 "os"
12 "path/filepath"
13
14 "golang.org/x/exp/shiny/iconvg"
15 )
16
17 func Example() {
18 ivgData, err := os.ReadFile(filepath.FromSlash("testdata/action-info.lores.ivg"))
19 if err != nil {
20 log.Fatal(err)
21 }
22
23 const width = 24
24 dst := image.NewAlpha(image.Rect(0, 0, width, width))
25 var z iconvg.Rasterizer
26 z.SetDstImage(dst, dst.Bounds(), draw.Src)
27 if err := iconvg.Decode(&z, ivgData, nil); err != nil {
28 log.Fatal(err)
29 }
30
31 const asciiArt = ".++8"
32 buf := make([]byte, 0, width*(width+1))
33 for y := 0; y < width; y++ {
34 for x := 0; x < width; x++ {
35 a := dst.AlphaAt(x, y).A
36 buf = append(buf, asciiArt[a>>6])
37 }
38 buf = append(buf, '\n')
39 }
40 os.Stdout.Write(buf)
41
42 // Output:
43 // ........................
44 // ........................
45 // ........++8888++........
46 // ......+8888888888+......
47 // .....+888888888888+.....
48 // ....+88888888888888+....
49 // ...+8888888888888888+...
50 // ...88888888..88888888...
51 // ..+88888888..88888888+..
52 // ..+888888888888888888+..
53 // ..88888888888888888888..
54 // ..888888888..888888888..
55 // ..888888888..888888888..
56 // ..888888888..888888888..
57 // ..+88888888..88888888+..
58 // ..+88888888..88888888+..
59 // ...88888888..88888888...
60 // ...+8888888888888888+...
61 // ....+88888888888888+....
62 // .....+888888888888+.....
63 // ......+8888888888+......
64 // ........++8888++........
65 // ........................
66 // ........................
67 }