Skip to content

Instantly share code, notes, and snippets.

@tmtk75
Last active December 19, 2015 12:19
Show Gist options
  • Select an option

  • Save tmtk75/5953654 to your computer and use it in GitHub Desktop.

Select an option

Save tmtk75/5953654 to your computer and use it in GitHub Desktop.
//http://go-tour-jp.appspot.com/#35
package main
import "code.google.com/p/go-tour/pic"
func f0(x, y int) uint8 {return uint8(x^y)}
func f1(x, y int) uint8 {return uint8((x+y)/2)}
func f2(x, y int) uint8 {return uint8(x*y)}
func Pic(dx, dy int) [][]uint8 {
f := f0
a := make([][]uint8, dy)
for i := 0; i < len(a); i++ {
r := make([]uint8, dx)
for j := 0; j < len(r); j++ {
r[j] = f(j, i)
}
a[i] = r
}
return a
}
func main() {
pic.Show(Pic)
}
@koron

koron commented Jul 9, 2013

Copy link
Copy Markdown

私が書くならこうかな。

for i, _ := range a {
    // ...
    a[i] = r
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment