Implementation of the exercise: Slices in “A Tour of Go”


When you begin to learn the trending Go lang you may have encounter with the Slice exercise which will ask you to draw an image based on slices. Here is how I implemented it.

package main
import (
func Pic(dx, dy int) [][]uint8 {
pixel := make([][]uint8, dy)
data := make([]uint8, dx)
for i := range pixel {
for j := range data {
data[j] = uint8((i+j)/2)
pixel[i] = data
return pixel
func main() {