Created
April 28, 2019 09:19
-
-
Save peterhellberg/b68ca4405195914ca7a0ecf18bcbf17e to your computer and use it in GitHub Desktop.
Grayscale ASCII color ramp from http://paulbourke.net/dataformats/asciiart/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
Author
peterhellberg
commented
Apr 29, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment