Last active
December 17, 2015 01:19
-
-
Save timbogit/5527555 to your computer and use it in GitHub Desktop.
Go exercise for "Slices"
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 "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