Skip to content

Instantly share code, notes, and snippets.

@paulohrpinheiro
Last active June 6, 2023 18:04
Show Gist options
  • Save paulohrpinheiro/5d590602f8960057f26b70094a82d758 to your computer and use it in GitHub Desktop.
Save paulohrpinheiro/5d590602f8960057f26b70094a82d758 to your computer and use it in GitHub Desktop.
GOLANG program to create png files
package main
import (
"image"
"image/color"
"image/png"
"os"
)
const (
size = 301
fileName = "draw.png"
)
var palette = []color.Color{
color.RGBA{0xaf, 0xaf, 0xff, 0xff},
color.RGBA{0xaf, 0xff, 0xaf, 0xee},
}
func main() {
rect := image.Rect(0, 0, size, size)
img := image.NewPaletted(rect, palette)
for x := 0; x < size; x++ {
for y := 0; y < size; y++ {
if visible(x, y) {
img.SetColorIndex(x, y, 1)
}
}
}
f, err := os.Create(fileName)
if err != nil {
panic(err)
}
defer f.Close()
png.Encode(f, img)
}
func visible(x int, y int) bool {
value := x*x + y*y
module := value % 10
if module == 0 {
return true
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment