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. Android ListView相关 头和尾 headView footerView

    ListView还可以添加头和尾部,而这头和尾就是View对象, 可以使用listView.addHeadView(view)方法和listView.addFootView(view)方法分别添加头和 ...

  2. highChartTable 切换

    <!doctype html> <html lang="en"> <head> <script type="text/javas ...

  3. java内存模型分析2

    不同线程之间无法直接访问对方工作内存中的变量,线程间变量值的传递均需要在主内存来完成,线程.主内存和工作内存的交互关系如下图所示,和上图很类似. 这里的主内存.工作内存与Java内存区域的Java堆. ...

  4. SQLite入门与分析(四)---Page Cache之事务处理(3)

    写在前面:由于内容较多,所以断续没有写完的内容. 11.删除日志文件(Deleting The Rollback Journal)一旦更改写入设备,日志文件将会被删除,这是事务真正提交的时刻.如果在这 ...

  5. AD15高版软件卡不卡,问题解决大讨论

    AD高版软件很卡(包括13 14 15版),这是我遇到过的问题,大家都遇到过的问题, 这里我分享一个解决办法:也请给位有什么好的方法也一起分享. 问题1卡:打开AD15软件, 按住鼠标中键 放大 或 ...

  6. eclipse中的输入提示怎么设置

    对于大多数的开发人员来说,打代码是一件非常繁琐的事情,eclipse中为我们提供了自动提示的功能,但是默认的提示只有当我们输入小数点后才能出现提示框,那么我们如何设置eclipse,能够让它为我们提示 ...

  7. POJ1942——Paths on a Grid(组合数学)

    Paths on a Grid DescriptionImagine you are attending your math lesson at school. Once again, you are ...

  8. SQL查询性能分析之(not in)、(and not)、()、(!=)性能比较

    SQL查询性能分析之(not in).(and not).().(!=)性能比较 SQL Server Bruce 3年前 (2013-01-08) 3284浏览 0评论 <:article c ...

  9. ServletContext对象

    **1 ServletContext对象   1)在web应用中,由服务器创建的唯一的一个对象是ServletContext   2)ServletContext对象在每一个Servlet中取得都是相 ...

  10. Ubuntu12.04 VMware Tools的安装

    Ubuntu12.04VMware Tools的安装 备注:xp+VMware.Workstation.v8.0.3 1.      VMware Tools的概述 VMware Tools是VMwa ...