Skip to content

Instantly share code, notes, and snippets.

@akira093
Created April 25, 2014 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akira093/11286914 to your computer and use it in GitHub Desktop.
Save akira093/11286914 to your computer and use it in GitHub Desktop.
package main
import (
"image"
"image/color"
"image/png"
"math"
"os"
)
func airy(x, y int) color.Gray16 {
s := math.Pow(float64(340-x), 2) + math.Pow(float64(240-y), 2)
return color.Gray16{uint16(s)}
}
func main() {
f, ferr := os.Create("test.png")
defer f.Close()
if ferr != nil {
panic(ferr)
}
rect := image.Rect(0, 0, 640, 480)
gray := image.NewGray16(rect)
for i := 0; i < 640; i++ {
for j := 0; j < 480; j++ {
gray.SetGray16(i, j, airy(i, j))
}
}
err := png.Encode(f, gray)
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment