Skip to content

Instantly share code, notes, and snippets.

@guoxingx
Created May 18, 2018 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guoxingx/2f548267e7abeeed3ff61b3af7a9bc2f to your computer and use it in GitHub Desktop.
Save guoxingx/2f548267e7abeeed3ff61b3af7a9bc2f to your computer and use it in GitHub Desktop.
A Tour of Go - Exercise: Images
package main
import (
"golang.org/x/tour/pic"
"image"
"image/color"
)
type Image struct{}
func (img Image) Bounds () (image.Rectangle) {
return image.Rect(0, 0, 100, 100)
}
func (img Image) ColorModel () (color.Model) {
return color.RGBAModel
}
func (img Image) At (x, y int) (color.Color) {
return color.RGBA{uint8(x / (y + 1)), uint8(x * y), 255, 255}
}
func main() {
m := Image{}
pic.ShowImage(m)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment