.。oO(さっちゃんですよヾ(〃l _ l)ノ゙☆)

.。oO(此のblogは、主に音樂考察Programming に分類されますよ。ヾ(〃l _ l)ノ゙♬♪♡)

音樂は SoundCloud に公開中です。

考察は現在は主に Scrapbox で公表中です。

Programming は GitHub で開發中です。

#golang §44 Exercise: Slices

A Tour of Go chapter 44

Exercise: Slices

Implement Pic. It should return a slice of length dy, each element of which is a slice of dx 8-bit unsigned integers. When you run the program, it will display your picture, interpreting the integers as grayscale (well, bluescale) values.
The choice of image is up to you. Interesting functions include x^y, (x+y)/2, and x*y.
(You need to use a loop to allocate each uint8 inside the []uint8.)
(Use uint8(intValue) to convert between types.)


package main

import "code.google.com/p/go-tour/pic"

func Pic(dx, dy int) [][]uint8 {
	pic := make([][]uint8, dx, dy)
	for iy := 0; iy < dy; iy++ {
		row := make([]uint8, dx)
		for ix := 0; ix < dx; ix++ {
			row[ix] = uint8((ix + iy) / 2)
		pic[iy] = row
	return pic

func main() {