Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Created April 28, 2019 09:19
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 peterhellberg/b68ca4405195914ca7a0ecf18bcbf17e to your computer and use it in GitHub Desktop.
Save peterhellberg/b68ca4405195914ca7a0ecf18bcbf17e to your computer and use it in GitHub Desktop.
Grayscale ASCII color ramp from http://paulbourke.net/dataformats/asciiart/
package main
import "github.com/peterhellberg/gfx"
const w, h = 16, 16
const ramp = " .:-=+*#%@"
func main() {
m := gfx.NewGray(gfx.IR(0, 0, w, h))
scaler := gfx.NewLinearScaler().
Range(0, float64(len(ramp)-1)).Domain(0, 255)
for x := 0; x < w; x++ {
for y := 0; y < h; y++ {
m.Set(x, y, gfx.ColorGray(uint8(x*16^y*16)))
i := int(m.GrayAt(x, y).Y)
n := int(scaler.ScaleFloat64(float64(i)))
s := string(ramp[n])
gfx.Printf("%s%s", s, s)
}
gfx.Printf("\n")
}
gfx.SavePNG("/tmp/gfx-ASCII-color-ramp.png", gfx.NewScaledImage(m, 32))
}
@peterhellberg
Copy link
Author

peterhellberg commented Apr 29, 2019

gfx-ASCII-color-ramp.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment