Skip to content

Instantly share code, notes, and snippets.

@paulohrpinheiro paulohrpinheiro/draw.go
Last active Feb 18, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.