Skip to content

Instantly share code, notes, and snippets.

@zhjgithub
Last active January 25, 2018 05:26
Show Gist options
  • Save zhjgithub/dc7e9b120ef746617c502735bad8e729 to your computer and use it in GitHub Desktop.
Save zhjgithub/dc7e9b120ef746617c502735bad8e729 to your computer and use it in GitHub Desktop.
package main
import "golang.org/x/tour/pic"
func Pic(fun func(x, y int) int) func(dx, dy int) [][]uint8 {
f := func(dx, dy int) [][]uint8 {
p := make([][]uint8, dy)
for i := 0; i < dy; i++ {
p[i] = make([]uint8, dx)
for j := 0; j < dx; j++ {
p[i][j] = uint8(fun(i, j))
}
}
return p
}
return f
}
func main() {
pic.Show(Pic(Formula2))
}
func Formula1(x, y int) int {
return (x + y) / 2
}
func Formula2(x, y int) int {
return x * y
}
func Formula3(x, y int) int {
return x ^ y
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment