Recently, I started to study go language, and practiced the topic of slice in go guide

Exercise: slicing
Implement pic. It should return a slice of length Dy, where each element is a slice of length DX and element type uint8. When you run this program, it interprets each integer as a grayscale value (well, actually the blue value) and displays its corresponding image.

The choice of images is up to you. Several interesting functions include (x + y) / 2, X * y, x ^ y, X * log (y) and X% (y + 1).

(tip: you need to use a loop to allocate each of the [] uint8 in [] uint8; use uint8 (intvalue) to convert between types; you may use functions in the math package.)

 

 

package main

import "golang.org/x/tour/pic"

func Pic(dx, dy int) [][]uint8 {
    a:=make([][]uint8,dy)
     for x := range a{
        b := make([]uint8,dx)
        for y := range b{
            b[y] = uint8(x*y)
        }
        a[x] = b
    }
    return a
}

func main() {
    pic.Show(Pic)
}