Last active
September 29, 2018 08:38
-
-
Save sighmin/9173886 to your computer and use it in GitHub Desktop.
Go tour "Pic" method: http://tour.golang.org
This file contains hidden or 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 ( | |
| "fmt" | |
| "code.google.com/p/go-tour/pic" | |
| ) | |
| // Return a matrix of uint8's to be drawn | |
| func Pic(dx, dy int) [][]uint8 { | |
| fmt.Println("Image size") | |
| fmt.Printf("x:%d, y:%d\n", dx, dy) | |
| // allocate slice | |
| picture := make([][]uint8, dx) | |
| for i := 0; i < dx; i++ { | |
| // allocate slice | |
| row := make([]uint8, dy, dy) | |
| for j := 0; j < len(row); j++ { | |
| // Do some crazy things | |
| row[j] = uint8((i+j)/2) | |
| row[len(row)-j-1] = row[j] ^ uint8(i*j) | |
| } | |
| picture[i] = row | |
| } | |
| return picture | |
| } | |
| func main() { | |
| pic.Show(Pic) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment