Skip to content

Instantly share code, notes, and snippets.

@Potherca
Last active June 14, 2022 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Potherca/40379ee258f82eaef6100fa5a9f46b20 to your computer and use it in GitHub Desktop.
Save Potherca/40379ee258f82eaef6100fa5a9f46b20 to your computer and use it in GitHub Desktop.
Output an ASCII string as SVG string in Go using https://github.com/asciitosvg/asciitosvg -- Run live at: https://go.dev/play/p/t2TBmJ9Rpfl
package main
import (
"fmt"
"github.com/asciitosvg/asciitosvg"
)
const logo = ` .-------------------------.
| |
| .---.-. .-----. .-----. |
| | .-. | +--> | | <--+ |
| | '-' | | <--+ +--> | |
| '---'-' '-----' '-----' |
| ascii 2 svg |
| |
'-------------------------'
https://github.com/asciit
osvg
[1,0]: {"fill":"#88d","a2s:delref":1}
`
func main() {
input := []byte(logo)
font := "Consolas,Monaco,Anonymous Pro,Anonymous,Bitstream Sans Mono,monospace" // Font family to use
noBlur := false // Disable drop-shadow blur
scaleX := 9 // X grid scale in pixels
scaleY := 16 // Y grid scale in pixels
tabWidth := 8 // Tab width.
canvas, err := asciitosvg.NewCanvas(input, tabWidth, true)
if err == nil {
svg := asciitosvg.CanvasToSVG(canvas, noBlur, font, scaleX, scaleY)
fmt.Printf("%s\n", svg)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment