Skip to content

Instantly share code, notes, and snippets.

@c-yan
Created January 18, 2018 21:56
Show Gist options
  • Select an option

  • Save c-yan/9a829ed7e1db77a0da58345d8a35397e to your computer and use it in GitHub Desktop.

Select an option

Save c-yan/9a829ed7e1db77a0da58345d8a35397e to your computer and use it in GitHub Desktop.
[A Tour of Go] Exercise: Images
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