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 ...
随机推荐
- POJ1151+线段树+扫描线
/* 线段树+扫描线+离散化 求多个矩形的面积 */ #include<stdio.h> #include<string.h> #include<stdlib.h> ...
- Google Play市场考察报告
考察了Google Play日本市场的10款应用,考察的重点在于每个App有什么亮点,盈利模式在哪里.本文并不是App的功能介绍. (1)恋爱文集[文库类应用] 该应用收录了一些恋爱文章,其主要受众是 ...
- Google chrome的字体设置
http://blog.sina.com.cn/s/blog_a3b863da01016sv3.html 谷歌浏览器(Google chrome)速度很快,很好用.问题是字体显示有时候不对:用英文版的 ...
- http://www.cnblogs.com/doit8791/p/4093808.html
http://www.cnblogs.com/doit8791/p/4093808.html
- spring结合时,web.xml的配置
<!-- 1. web.xml配置 <context-param> <param-name>webAppRootKey</param-name> <pa ...
- nginx知识点
nginx 安装与配置文件 #cat /etc/nginx/nginx.conf #运行用户user www-data; #启动进程,通常设置成和cpu的数量相等worker_processes ...
- ArcGIS学习记录—Arcgis中点、线、面的相互转换方法
本文使用的工具在Arctoolbox.Data Management Tools.Features (一)面--面转线.面转点 面转线 Polygon To Line .Feature To Lin ...
- 算法总结之欧拉函数&中国剩余定理
算法总结之欧拉函数&中国剩余定理 1.欧拉函数 概念:在数论,对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目. 通式:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)( ...
- 7个鲜为人知却超实用的PHP函数
PHP有许多内置函数,其中大多数函数都被程序员广泛使用.但也有一些函数隐藏在角落,本文将向大家介绍7个鲜为人知,但用处非常大的函数. 没用过的程序员不妨过来看看. 1.highlight_string ...
- 使用dreamever去掉文件头部BOM(bom)信息 From 百度经验
本文来此百度经验: 地址为:http://jingyan.baidu.com/article/3f16e003c3dc172591c103e6.html OM主要处理浏览器窗口与框架,但事实上,浏览器 ...