Created
April 4, 2015 18:24
-
-
Save evandertino/c051f6e130222ce829aa to your computer and use it in GitHub Desktop.
Go Exercise: Images - http://tour.golang.org/methods/16
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" | |
| "image" | |
| "image/color" | |
| ) | |
| type Image struct { | |
| Width, Height int | |
| color uint8 | |
| } | |
| func (this *Image) ColorModel() color.Model { | |
| return color.RGBAModel | |
| } | |
| func (this *Image) Bounds() image.Rectangle { | |
| return image.Rect(0, 0, this.Width, this.Height) | |
| } | |
| func (this *Image) At(x, y int) color.Color { | |
| return color.RGBA{this.color + uint8(x), this.color + uint8(y), 255, 255} | |
| } | |
| func main() { | |
| m := Image{100, 100, 128} | |
| pic.ShowImage(&m) | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment