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 callpic.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 main

import (
"code.google.com/p/go-tour/pic"
"image"
"image/color"
) type Image struct{} func (img Image) ColorModel() color.Model {
return color.RGBAModel
} func (img Image) Bounds() image.Rectangle {
return image.Rect(, , , )
} func (img Image) At(x, y int) color.Color {
return color.RGBA{uint8(x), uint8(y), , }
} func main() {
m := Image{}
pic.ShowImage(m)
}

A Tour of Go Exercise: Images的更多相关文章

  1. A Tour of Go Exercise: HTTP Handlers

    Implement the following types and define ServeHTTP methods on them. Register them to handle specific ...

  2. A Tour of Go Exercise: Errors

    Copy your Sqrt function from the earlier exercises and modify it to return an error value. Sqrt shou ...

  3. A Tour of Go Exercise: Fibonacci closure

    Let's have some fun with functions. Implement a fibonacci function that returns a function (a closur ...

  4. 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 ...

  5. 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 u ...

  6. 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 ...

  7. exercise.tour.go google的go官方教程答案

    /* Exercise: Loops and Functions #43 */ package main import ( "fmt" "math" ) fun ...

  8. A Tour of Go Advanced Exercise: Complex cube roots

    Let's explore Go's built-in support for complex numbers via the complex64 and complex128 types. For ...

  9. 软件测试:3.Exercise Section 2.3

    软件测试:3.Exercise Section 2.3 /************************************************************ * Finds an ...

随机推荐

  1. POJ3258River Hopscotch(二分)

    http://poj.org/problem?id=3258 题意:有一条很长很直的河距离为L,里边有n块石头,不包括起点和终点的那两块石头,奶牛们会从一个石头跳到另外一个,但因为有的石头隔得太近了, ...

  2. UR #13 Yist

    第一次打UR,打了一个半小时就弃疗了QAQ 这是我唯一一道考试的时候做出来的题目,其他两道连暴力都懒得写了 很容易发现对于每个要删除的点 我们找到左边第一个比他小的不用删除的点,右边第一个比他小的不用 ...

  3. live555源码研究(十)------在编译过程中遇到的问题及解决方法

    一.编译testOnDemandRTSPServer.cpp. 在testProgs项目中,加入testOnDemandRTSPServer.cpp进行编译,编译类型是编译成exe文件,在编译过程中会 ...

  4. James搭建邮件服务器

    来源:http://chenfengcn.iteye.com/blog/356874   1 关于James与Javamail Apache James(Java Apache Mail Enterp ...

  5. TCP/IP的三次握手和四次分手以及超时机制

    使用INADDR_ANY的时候,往往针对多网卡情况,采用tcp连接方式,需要选择使用哪一个网卡发送,自己猜想应该是使用三次握手机制,如何判断目标地址不可达,应该使用的是超时机制,即握手超时则不可到达. ...

  6. 关于web会话中的session过期时间的设置

    关于web会话中的session过期时间的设置 1.操作系统: 步骤:开始——〉管理工具——〉Internet信息服务(IIS)管理器——〉网站——〉默认网站——〉右键“属性”——〉主目录——〉配置— ...

  7. 解决项目中EF5.0升级到EF6.0无法安装包的方法

    今天在vs2012上新建了一个mvc4的项目,mvc4中默认的Entity Framework是5.0的版本,如下所示: 或者:,但是项目中有些要用到EF6.0的相关方法,用EF5.0实在繁琐,于是在 ...

  8. LBS云端数据删除和上传

    这里采用C#模拟表单提交,实现LBS云端删除和csv格式文件的上传. 删除: /// <summary> /// 从LBS云端删除数据 /// </summary> /// & ...

  9. JQuery向ashx提交中文参数方案

    客户端://异步获取数据var tpAction=action+'getSearch.ashx?key='+encodeURIComponent('中国'); $.getJSON(tpAction,f ...

  10. MySQL索引的查看创建和删除

    1.索引作用 在索引列上,除了上面提到的有序查找之外,数据库利用各种各样的快速定位技术,能够大大提高查询效率.特别是当数据量非常大,查询涉及多个表时,使用索引往往能使查询速度加快成千上万倍. 例如,有 ...