Skip to content

Instantly share code, notes, and snippets.

@timbogit
Last active December 17, 2015 01:19
Show Gist options
  • Save timbogit/5527555 to your computer and use it in GitHub Desktop.
Save timbogit/5527555 to your computer and use it in GitHub Desktop.
Go exercise for "Slices"
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
// allocate 'dy' row slices of []unit8
rows := make([][]uint8, dy)
for i, row := range rows {
// allocate 'dx' uint8 points in each row
row = make([]uint8, dx)
for j, _ := range row {
// place values into each point
row[j] = uint8(i * j) // try also: (i ^ j) or (i+j)/2
}
rows[i] = row
}
return rows
}
func main() {
pic.Show(Pic)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment