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 ...
随机推荐
- IDEA 创建maven-web project失败一例
今天使用IDEA创建WEB-APP总是失败,经排查原来是MAVEN环境没配置好!!! 配置: M2_HOME--->maven解压目录 path---->%M2_HOME%\bin\
- 使用IntelliJ Idea创建Spring MVC项目
- 102. Binary Tree Level Order Traversal
题目: Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to ri ...
- Kali2.0 Sqlmap清除历史扫描日志
使用Sqlmap扫描SQL注入漏洞时,首次扫描会在SQL的/root/.sqlmap/output/目录下留下 以IP地址为名称的文件夹,如下所示: 而如果该安全漏洞经过修复后,再次使用SQLMAP扫 ...
- c#自带压缩类实现数据库表导出到CSV压缩文件的方法
在导出大量CSV数据的时候,常常体积较大,采用C#自带的压缩类,可以方便的实现该功能,并且压缩比例很高,该方法在我的开源工具DataPie中已经经过实践检验.我的上一篇博客<功能齐全.效率一流的 ...
- 【HDOJ】3553 Just a String
后缀数组加二分可解. /* 3553 */ #include <iostream> #include <sstream> #include <string> #in ...
- C# 判断两张图片是否一致的快速方法
#region 判断图片是否一致 /// <summary> /// 判断图片是否一致 /// </summary> /// <param name="img& ...
- Welcome to Linux From Scratch!
/**************************************************************************** * Welcome to Linux Fro ...
- Jquery拖拽原理
/* onmousedown : 选择元素 onmousemove : 移动元素 onmouseup : 释放元素 */ 查看Demo:拖拽图片 function drag(obj) { obj.on ...
- 白话spring依赖注入
Spring能有效地组织J2EE应用各层的对象.Action?Service?DAO?,都可在Spring的管理下有机地协调.运行.Spring将各层的对象以松耦合的方式组织在一起,对象与对象之间没有 ...