Skip to content

Instantly share code, notes, and snippets.

@cockscomb
Last active December 28, 2015 07:39
Show Gist options
  • Save cockscomb/7465620 to your computer and use it in GitHub Desktop.
Save cockscomb/7465620 to your computer and use it in GitHub Desktop.
package main
import (
"math"
"code.google.com/p/go-tour/pic"
)
func Pic(dx, dy int) [][]uint8 {
pic := make([][]uint8, dy)
for y := range pic {
pic[y] = make([]uint8, dx)
for x := range pic[y] {
half_dx := float64(dx) / 2
half_dy := float64(dy) / 2
_x := (float64(x) - half_dx) / half_dx
_y := (float64(y) - half_dy) / half_dy
theta := math.Atan(_x / _y)
pixel := theta / math.Pi
pic[y][x] = uint8(pixel * 128 + 128)
}
}
return pic
}
func main() {
pic.Show(Pic)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment