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. 在NEXUS中加入自己定义的第三方PROXIES代理库

    就是要等会耐心,更新好之后,才能在PUBLIC库里进行操作. 下图是JBOSS的

  2. 深入剖析Classloader(二)--根类加载器,扩展类加载器与系统类加载器

    原文地址:http://yhjhappy234.blog.163.com/blog/static/31632832201152555245584/?suggestedreading&wumii ...

  3. 初始化D3D设备

    bool initD3D(HWND hWnd) { // 主要目的是获取设备,为调用下面的函数做很多准备. // 比如 获取IDirect3D9 ,获取支持的顶点处理,填充后备缓冲相关参数等. // ...

  4. R语言学习笔记:数据的可视化

    本文参考数据挖掘与R第二章节 读入数据 方法1,下载Data mining with r的配套包 install.packages('DMwR') 方法2,下载txt数据,并且读入数据.方法见上文. ...

  5. 深入理解ob_flush和flush的区别

    ob_flush/flush在手册中的描述, 都是刷新输出缓冲区, 并且还需要配套使用, 所以会导致很多人迷惑… 其实, 他们俩的操作对象不同, 有些情况下, flush根本不做什么事情.. ob_* ...

  6. Python学习笔记一--字符串的使用

    一.基本操作 1. 合并字符串:“+” 2. 打印重复的字符串:"*"      3. 按位获取字符串中的字符:索引      4. 按位获取字符串中的子字符串:分片      5 ...

  7. RTDX target application does not match emulation protocol!

    2013-06-20 10:19:22 在CCS2.0 的emulator写dsp/bios 的程序,编译链接无错误,而点击LOAD Program下载xxx.out完成时弹出如下对话框: RTDX ...

  8. 【开源推荐】AllJoyn:打造全球物联网的通用开源框架

    摘要:随着智能设备的发展,物联网逐渐进入了人们的生活.据预测,未来几乎一切东西(超过500亿台设备)都可以互联.高通公司发布了开源项目AllJoyn,这是一个能够使连接设备间进行互操作的通用软件框架和 ...

  9. python web开发遇到socket.error[errno 10013]

    socket.error[errno 10013],端口被占用 重新换一个端口,或者把占用该端口的程序关闭就可以了

  10. 第一部分 Android MediaPlayer 概述

    [IT168 技术文档]本文主要介绍的是Android中很重要也最为复杂的媒体播放器(MediaPlayer)部分的架构.对于Android这样一个完整又相对复杂的系统,一个MediaPlayer功能 ...