Created
November 14, 2013 11:54
-
-
Save hitode909/7465602 to your computer and use it in GitHub Desktop.
http://tour.golang.org/#36 #gohakobe
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 "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