A Tour of Go 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 {
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的更多相关文章
- 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 ...
- A Tour of Go Making slices
Slices are created with the make function. It works by allocating a zeroed array and returning a sli ...
- A Tour of Go Slicing slices
---恢复内容开始--- Slices can be re-sliced, creating a new slice value that points to the same array. The ...
- A Tour of Go Exercise: Images
Remember the picture generator you wrote earlier? Let's write another one, but this time it will ret ...
- A Tour of Go Exercise: HTTP Handlers
Implement the following types and define ServeHTTP methods on them. Register them to handle specific ...
- A Tour of Go Exercise: Errors
Copy your Sqrt function from the earlier exercises and modify it to return an error value. Sqrt shou ...
- A Tour of Go Exercise: Fibonacci closure
Let's have some fun with functions. Implement a fibonacci function that returns a function (a closur ...
- 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 ...
- 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 ...
随机推荐
- Google chrome的字体设置
http://blog.sina.com.cn/s/blog_a3b863da01016sv3.html 谷歌浏览器(Google chrome)速度很快,很好用.问题是字体显示有时候不对:用英文版的 ...
- iOS利用HealthKit框架从健康app中获取步数信息
微信和QQ的每日步数最近十分火爆,我就想为自己写的项目中添加一个显示每日步数的功能,上网一搜好像并有相关的详细资料,自己动手丰衣足食. 统计步数信息并不需要我们自己去实现,iOS自带的健康app已经为 ...
- 去除右键菜单opendlg
环境:windows8.1专业版 未知文件类型,右键会多出一个opendlg的选项!下面是移除的方法: 将下面的内容复制到记事本,并另存为XXX .reg,导入注册表即可! Windows Reg ...
- GCC编译警告和错误
1 error: expected expression before 'else' else之前无表达式. 2 error: lvalue required as left operand of a ...
- [转] Windows下使用Python读取Excel表格数据
http://www.python-excel.org/这个网站罗列了很多关于在Python下操作Excel文件的信息,这里选择了其介绍的第一个模块xlrd . xlrd 0.9.2版本跨平台同时支持 ...
- 需要保存数据zabbix,不需要保存数据nagios
需要保存数据zabbix,不需要保存数据nagios cacti 有什么好用的基于Web的Linux系统监控开源工具(网管系统) 要求类似于Ubuntu的Landscape,可以记录下历史CPU数值. ...
- Fody
Fody https://github.com/Fody/Fody/ 有空还要看下怎么实现的.
- Unity3D集成SVN进行版本控制
首先,AssetServer确实很好用,Unity内部集成的管理界面,操作很简单,提交冲突的后还可以进行文件比对.但学习使用过程中,发现文件体积较大的项目文件目录(600M),我提交不上去,会返回没有 ...
- 西南科技大学第十届ACM程序设计竞赛题解
A.德州扑克 B. 我恨11(1089) 问题描述 11是一个孤独的数字,小明十分讨厌这个数字,因此如果哪个数字中出现了11或者该数字是11的倍数,他同样讨厌这个数字.现在问题来了,在闭区间[L,R] ...
- RMAN catalog备份恢复方案
对于数据库的稳定性,高可用,跨平台以及海量数据库的处理,Oracle 数据库通常是大型数据库和大企业的首选.尽管如此,仍然不乏很多中小企业想要品尝一下Oracle腥味,因此在Oracle环境中也有不少 ...