【GoLang笔记】A Tour of Go - Exercise: Images
来源:互联网 发布:淘宝如何入驻亲宝贝 编辑:程序博客网 时间:2024/06/05 05:08
本笔记是GoLang学习教程的一道习题,题目要求及一种参考实现如下所示。
备注:由于天朝GFW屏蔽了GAE,所以GoLang官网及学习教程需要翻墙才能访问。
Exercise: Images
Remember the picture generator you wrote earlier? Let's write another one, but this time it will return an implementation of image.Image instead of a slice of data.
Define your own Image type, implement the necessary methods, and call pic.ShowImage.
Bounds should return a image.Rectangle, like image.Rect(0, 0, w, h).
ColorModel should return color.RGBAModel.
At should return a color; the value v in the last picture generator corresponds to color.RGBA{v, v, 255, 255} in this one.
参考实现如下:
package mainimport ( "code.google.com/p/go-tour/pic" "image" "image/color")type Image struct{ x, y, w, h int v uint8}func (img Image) ColorModel() color.Model { return color.RGBAModel}func (img Image) Bounds() image.Rectangle { return image.Rect(0, 0, img.w, img.h)}func (img Image) At(x, y int) color.Color { return color.RGBA{img.v, img.v, 255, 255}}func main() { m := Image{1, 2, 200, 30, 11} pic.ShowImage(m)}
========================= EOF ===================
0 0
- 【GoLang笔记】A Tour of Go - Exercise: Images
- 【GoLang笔记】A Tour of Go - Exercise: Equivalent Binary Trees
- 【GoLang笔记】A Tour of Go - Exercise: Web Crawler
- A Tour of Go: Exercise: Rot13 Reader
- A Tour of Go---Exercise: Fibonacci closure
- golang官方指导练习(go tour exercise)
- A Tour of Golang (二)
- 【Go语言(golang)教程】A Tour of Go 七十集大全
- go语言Exercise: Images
- A Tour of Golang (一)
- A Tour of Go Named results
- A tour of Go的疑问
- A Tour of C++
- 《CS:APP》 chapter 1 A Tour of Computer Systems 笔记
- Chapter 1 A Tour of Computer Systems 《CSAPP》笔记
- A.Bug.Hunters.Diary.A.Guided.Tour.Through.the.Wilds.of.Software.Security 笔记
- Creating a Set of Training Images
- Introduction A Guided Tour of the POCO
- D3D 调试
- Java系列(十三)__Java新特性(泛型、枚举、Annotation)
- 在struts中获得请求的方式
- SSH互信
- 初学Python之如何遍历列表元素
- 【GoLang笔记】A Tour of Go - Exercise: Images
- BZOJ1029 [JSOI2007]建筑抢修(贪心+堆)
- Java系列(十四)__多线程
- JAVA 代理模式
- VBA参照如下地址学习
- [暖手][学习阶段-各路杂题][HDU-1235]统计同成绩学生人数
- iOS开发-Protocol协议及委托代理(Delegate)传值
- 消息推送(APNS)
- Installation error: INSTALL_FAILED_VERSION_DOWNGRADE