Skip to content

Instantly share code, notes, and snippets.

@yixiaoyx
Created November 28, 2018 23:58
Show Gist options
  • Save yixiaoyx/1b86860e5164938404615d2d25607c97 to your computer and use it in GitHub Desktop.
Save yixiaoyx/1b86860e5164938404615d2d25607c97 to your computer and use it in GitHub Desktop.
// generates an image in grayscale
package main
import "golang.org/x/tour/pic"
// my solution
func Pic(dx, dy int) [][]uint8 {
p := make([][]uint8, dy)
for i := range p {
p[i] = make([]uint8, dx)
//p[i][int(i/2)] = 0xFF // this one draws a line
}
for x := range p {
for y := range p[x] {
//p[x][y] = uint8((x+y)/2*(x^y)) // combining two filters?
//p[x][y] = uint8(x*y)
p[x][y] = uint8(-x^y) // this is my favourite
//p[x][y] = uint8((x+y)/2)
}
}
return p
}
func main() {
pic.Show(Pic)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment