Last active
January 25, 2018 05:26
-
-
Save zhjgithub/dc7e9b120ef746617c502735bad8e729 to your computer and use it in GitHub Desktop.
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 "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