Created
January 18, 2018 21:56
-
-
Save c-yan/9a829ed7e1db77a0da58345d8a35397e to your computer and use it in GitHub Desktop.
[A Tour of Go] Exercise: Images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "golang.org/x/tour/pic" | |
| import "image" | |
| import "image/color" | |
| type MyImage struct { | |
| w int | |
| h int | |
| v uint8 | |
| } | |
| func (mi MyImage) ColorModel() color.Model { | |
| return color.RGBAModel | |
| } | |
| func (mi MyImage) Bounds() image.Rectangle { | |
| return image.Rect(0, 0, mi.w, mi.h) | |
| } | |
| func (mi MyImage) At(x, y int) color.Color { | |
| return color.RGBA{mi.v, mi.v, 255, 255} | |
| } | |
| func main() { | |
| m := MyImage{100, 100, 100} | |
| pic.ShowImage(m) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment