Skip to content

Instantly share code, notes, and snippets.

@MAJA-Lin
Forked from tetsuok/answer_pic.go
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MAJA-Lin/df24a5f5d356cb7a1378 to your computer and use it in GitHub Desktop.
Save MAJA-Lin/df24a5f5d356cb7a1378 to your computer and use it in GitHub Desktop.
From tetsuok/answer_pic.go An answer for [GO:Exercise: Slices] http://tour.golang.org/moretypes/14
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
// Allocate two-dimensioanl array.
a := make([][]uint8, dy)
for i := 0; i < dy; i++ {
a[i] = make([]uint8, dx)
}
// Do something.
for i := 0; i < dy; i++ {
for j := 0; j < dx; j++ {
switch {
case j % 15 == 0:
a[i][j] = 240
case j % 3 == 0:
a[i][j] = 120
case j % 5 == 0:
a[i][j] = 150
default:
a[i][j] = 100
}
}
}
return a
}
func main() {
pic.Show(Pic)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment