Skip to content

Instantly share code, notes, and snippets.

@m99coder
Created March 9, 2021 17:35
Show Gist options
  • Select an option

  • Save m99coder/105ca3481d09afce097fc84d808a5fe2 to your computer and use it in GitHub Desktop.

Select an option

Save m99coder/105ca3481d09afce097fc84d808a5fe2 to your computer and use it in GitHub Desktop.
2D slices in Go
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