Skip to content

Instantly share code, notes, and snippets.

@DQNEO
Created February 24, 2020 11:43
Show Gist options
  • Save DQNEO/e3635c64fd8e5f8d4fb14ad1742863a4 to your computer and use it in GitHub Desktop.
Save DQNEO/e3635c64fd8e5f8d4fb14ad1742863a4 to your computer and use it in GitHub Desktop.
dot image generator
package main
import (
"fmt"
"image"
"image/color"
"image/png"
"os"
)
var (
red = color.RGBA{255-32, 0, 0, 255}
yellow = color.RGBA{255,255,0,255}
orange = color.RGBA{255, 232, 150, 255}
pink = color.RGBA{255, 232, 232, 255}
face = color.RGBA{64,64, 128, 255}
black = color.RGBA{32, 32, 32, 255}
white = color.RGBA{255, 255, 255, 255}
scale = 1
)
func main() {
var cells = [][]color.RGBA{
{yellow , red, red, red },
{pink , orange, face, pink},
{orange, face, black,orange },
{red, black, red, black},
}
height := len(cells)
width := len(cells[0])
img := image.NewRGBA(image.Rect(0, 0, width*scale, height*scale))
for y:=0; y<height; y++ {
for x:= 0; x<width; x++ {
fmt.Printf("[%d][%d],", x, y)
img.Set(x,y, cells[y][x])
}
fmt.Printf("\n")
}
f, _ := os.Create("/tmp/img/a.png")
png.Encode(f, img)
f.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment