A Tour of Go 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 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的更多相关文章
- 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: Slices
Implement Pic. It should return a slice of length dy, each element of which is a slice of dx 8-bit u ...
- 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 ...
- exercise.tour.go google的go官方教程答案
/* Exercise: Loops and Functions #43 */ package main import ( "fmt" "math" ) fun ...
- 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 ...
- 软件测试:3.Exercise Section 2.3
软件测试:3.Exercise Section 2.3 /************************************************************ * Finds an ...
随机推荐
- web页面浮动回到顶部功能和浮动广告
实现测试浮动回到顶部 法一:用js实现<%@ Page Language="C#" AutoEventWireup="true" CodeBehind=& ...
- codeforces #313 div1 D
好神的题目! 首先我们运用pick定理A=S-B/2+1将要求的东西转化掉 之后分离变量,我们变成了求选取凸包面积的期望和求选取凸包在边界上的点的期望 我们先考虑求选取凸包面积的期望 如何计算凸多边形 ...
- cocos2d-x 锚点,位置==》动手实验记录 多动手... :)
总结: 1:cocos2d-x的位置由锚点和Position位置 共同决定的.2: cocos2d-x,当位置不设置或者为零的时候, 子节点的锚点位置永远位于父节点的左小角的地方3:我们的自己的游戏编 ...
- minicom 配置
问题: 1:不相应按键,只有打印 Hardware Flow Control 选择NO minicom显示中文的设置: env LANG=en_US minicom 可以 ...
- python脚本工具-2 去除扩展名后提取目录下所有文件名并保存
文件夹里有多个RM格式的视频文件,现需要把它们的文件名都提取出来,并去掉文件的扩展名,以便放到需要的网页里. 源代码: # --- picknames.py --- import os filenam ...
- 安装Hadoop系列 — 新建MapReduce项目
1.新建MR工程 依次点击 File → New → Ohter… 选择 “Map/Reduce Project”,然后输入项目名称:mrdemo,创建新项目: 2.(这步在以后的开发中可能 ...
- matlab 中保存某几个变量
save AOA.mat dingjiao RMSE%保存变量dingjiao,RMSE于AOA.mat clear all;%当删除所有数据之后 load AOA.mat%还可以读出这两个变量的数 ...
- 【.Net免费公开课】--授技.Net中的高帅富技术-"工作流"
课程简介 免费公开课主题: .Net中的高帅富技术-“工作流” 公开课开课时间: 10月17日 19:30--21:30 公开课YY频道: 85155393 (重要:公开课QQ ...
- mysql rr 查询出现的事务情况
select * from INFORMATION_SCHEMA.INNODB_TRX\G The INNODB_TRX table contains information about every ...
- 【HDOJ】3386 Final Kichiku “Lanlanshu”
数位DP.需要注意的是需要特殊处理前导0,另外连续的==匹配,不要计重了,尽量贪心的匹配掉. /* 3886 */ #include <iostream> #include <sst ...