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. HDU4548+素数

    简单题. /* */ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<alg ...

  2. poj 2265 Bee Maja

    题目的意思很容易理解.就是找两个不同坐标的对应关系.下面的思路转自POJ的论坛 首先,记由1到2的方向记为2,1到3的方向记为3……1到7的方向记为7,他们分别是:(0,1),(-1,1),(-1,0 ...

  3. linux 磁盘读写性能测试

    1. 测试读取速度 haparm -Tt /dev/xxx 1.1 获取硬盘设备名称: fdisk -l Disk /dev/xvdf: 365.0 GB, 365041287168 bytes 25 ...

  4. PHP简单语法

    PHP简单语法 声明变量 $var_name="1"; $var_num=1; $var_bool=true; var_dump"函数可以将我们的变量的数据类型显示出来. ...

  5. SQLite入门与分析(三)---内核概述(1)

    写在前面:从本章开始,我们开始进入SQLite的内核.为了能更好的理解SQLite,我先从总的结构上讨论一下内核,从全局把握SQLite很重要.SQLite的内核实现不是很难,但是也不是很简单.总的来 ...

  6. Struts-2.3.24.1官方例子-struts2-blank

    一.配置文件 1.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app id=&qu ...

  7. 如何设置table的border-radius?

    遇到一个诡异的问题, 为table添加border-radius不起作用. 示例如下: #table1 { border-collapse: collapse !important; border-r ...

  8. linux命令之-pstree使用说明

    pstree  shows running processes as a tree. The tree is rooted at either pid or init if pid is omitte ...

  9. Redpine的Lite-Fi解决方案获Wi-Fi CERTIFIED认证

    应用微电路公司(AMCC)和Redpine Signals日前共同宣布,已合作开发出新一代基于Power Architecture的嵌入式Wi-Fi连接性解决方案,目前双方已经在AMCC的PowerP ...

  10. 254 shades of grey

    254 shades of grey Description: Why would we want to stop to only 50 shades of grey? Let's see to ho ...