Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created November 14, 2013 11:54
Show Gist options
  • Save hitode909/7465602 to your computer and use it in GitHub Desktop.
Save hitode909/7465602 to your computer and use it in GitHub Desktop.
package main
import "math"
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
pic := make([][]uint8, dy)
for y := range pic {
line := make([]uint8, dx)
pic[y] = line
for x := range line {
centerX := dx/2.0
centerY := dy/2.0
distance := math.Sqrt(float64((centerX-x)*(centerX-x)+(centerY-y)*(centerY-y)))
color := 0
if (distance > float64(dx/2.0)) {
color = 255
} else {
color = 0
}
line[x] = uint8(color)
}
}
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