Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

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
You can’t perform that action at this time.