| 1 |
|
| 2 |
|
| 3 |
|
| 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 |
|
| 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 |
} |