c4se記:さっちゃんですよ☆

.。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.)

Example

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() {
	pic.Show(Pic)
}

付言

code.google.com/p/go-tour/picのコードは読まなくとも充分書ける。hintにあるように、行毎に[]uint8を初期化する必要がある。