Go exercises: Slices

GoLang tutorial has a task – Create slices for picture

package main

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

func Pic(dx, dy int) [][]uint8 {
	result := make([][]uint8,dy)
	for i:=range result {
		innerS := make([]uint8, dx)
		for j := range innerS {
			switch {
            case i*j % 15 == 0:
                innerS[j] = 240
            case i/j % 3 == 0:
                innerS[j] = 120
            case i*j % 5 == 0:
                innerS[j] = 150
            default:
                innerS[j] = 100
            }
		}
		result[i] = innerS
	}
	
	return result
}

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


here is the result

Leave a Reply

%d bloggers like this: