Last active
June 6, 2023 18:04
-
-
Save paulohrpinheiro/5d590602f8960057f26b70094a82d758 to your computer and use it in GitHub Desktop.
GOLANG program to create png files
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 ( | |
"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