Skip to content

Instantly share code, notes, and snippets.

@sighmin
Last active September 29, 2018 08:38
Show Gist options
  • Select an option

  • Save sighmin/9173886 to your computer and use it in GitHub Desktop.

Select an option

Save sighmin/9173886 to your computer and use it in GitHub Desktop.
Go tour "Pic" method: http://tour.golang.org
package main
import (
"fmt"
"code.google.com/p/go-tour/pic"
)
// Return a matrix of uint8's to be drawn
func Pic(dx, dy int) [][]uint8 {
fmt.Println("Image size")
fmt.Printf("x:%d, y:%d\n", dx, dy)
// allocate slice
picture := make([][]uint8, dx)
for i := 0; i < dx; i++ {
// allocate slice
row := make([]uint8, dy, dy)
for j := 0; j < len(row); j++ {
// Do some crazy things
row[j] = uint8((i+j)/2)
row[len(row)-j-1] = row[j] ^ uint8(i*j)
}
picture[i] = row
}
return picture
}
func main() {
pic.Show(Pic)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment