Created
March 9, 2021 17:35
-
-
Save m99coder/105ca3481d09afce097fc84d808a5fe2 to your computer and use it in GitHub Desktop.
2D slices in Go
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 "golang.org/x/tour/pic" | |
| func Pic(dx, dy int) [][]uint8 { | |
| r := make([][]uint8, dy) | |
| for y := range r { | |
| r[y] = make([]uint8, dx) | |
| for x := range r[y] { | |
| // different functions to generate the “picture” | |
| r[y][x] = uint8((x + y) / 2) | |
| r[y][x] = uint8(x * y) | |
| r[y][x] = uint8(x ^ y) | |
| } | |
| } | |
| return r | |
| } | |
| func main() { | |
| pic.Show(Pic) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment