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 {
s := make([][]uint8,dx)
for i := range s {
s[i] = make([]uint8,dy)
for j := range s[i]{
s[i][j] = uint8(i * j)
}
}
return s
} func main() {
pic.Show(Pic)
}
package main 

import "fmt"

func main() {
s := make([][]uint8,)
//创建的先是二维的
fmt.Println(s)//[[] [] [] [] [] [] [] [] [] []]
}

A Tour of Go Exercise: Slices的更多相关文章

  1. A Tour of Go Nil slices

    The zero value of a slice is nil. A nil slice has a length and capacity of 0. (To learn more about s ...

  2. A Tour of Go Making slices

    Slices are created with the make function. It works by allocating a zeroed array and returning a sli ...

  3. A Tour of Go Slicing slices

    ---恢复内容开始--- Slices can be re-sliced, creating a new slice value that points to the same array. The ...

  4. A Tour of Go Exercise: Images

    Remember the picture generator you wrote earlier? Let's write another one, but this time it will ret ...

  5. A Tour of Go Exercise: HTTP Handlers

    Implement the following types and define ServeHTTP methods on them. Register them to handle specific ...

  6. A Tour of Go Exercise: Errors

    Copy your Sqrt function from the earlier exercises and modify it to return an error value. Sqrt shou ...

  7. A Tour of Go Exercise: Fibonacci closure

    Let's have some fun with functions. Implement a fibonacci function that returns a function (a closur ...

  8. A Tour of Go Exercise: Maps

    Implement WordCount. It should return a map of the counts of each “word” in the string s. The wc.Tes ...

  9. A Tour of Go Exercise: Loops and Functions

    As a simple way to play with functions and loops, implement the square root function using Newton's ...

随机推荐

  1. 其实,前面倒腾那么多,只是为了想玩SPRING BOOT

    嘿嘿,,曲线达到.. 看来看来很多国内的速成,都不爽. 官方教程最体贴~~~:) http://docs.spring.io/spring-boot/docs/current/reference/ht ...

  2. HDU1180+BFS

    bfs思路:三维标记状态 && 处理好 - | 和时刻的关系即可 /* bfs 思路:三维标记状态 && 处理好 - | 和时刻的关系即可 */ #include< ...

  3. Java 方法覆盖和方法重载

    方法重载(overloaded),要求方法的名称相同,参数列表不相同. 方法覆盖(override),要求①方法名相同,②参数列表相同,③返回值相同 如果是方法覆盖,要注意以下几种情况: 1.子类方法 ...

  4. jquery的ajax向后台servlet传递json类型的多维数组

    后台运行结果:                                                                                      前台运行结果: ...

  5. POJ2586——Y2K Accounting Bug

    Y2K Accounting Bug   Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...

  6. RedMine项目管理系统安装问题(Linux版一键安装包)

    安装环境 操作环境:VMware下安装的Parrot Security OS 系统 使用软件:bitnami-redmine---linux-x64-installer.run 问题描述: 安装步骤与 ...

  7. svn merge部分的详细说明

    http://blog.sina.com.cn/s/blog_620eb3b20101hvz7.html 解决版本冲突-使用SVN主干与分支功能 1  前言 大多数产品开发存在这样一个生命周期:编码. ...

  8. Complete The Pattern #2

    Complete The Pattern #2 Description: Task: You have to write a function pattern which creates the fo ...

  9. C++中巧妙的位运算

    位运算要多想到与预算和异或运算,并常常将两个数对应位上相同和不同分开处理 一.x&(x-1)消除x二进制中最右边的一个1. 这个比较厉害,比如统计某个 二.与和异或的巧妙结合的思想 与运算可以 ...

  10. Mysql DBA 20天速成教程,DBA大纲

    Mysql DBA 20天速成教程 基本知识1.mysql的编译安装2.mysql 第3方存储引擎安装配置方法3.mysql 主流存储引擎(MyISAM/innodb/MEMORY)的特点4.字符串编 ...