Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@takatoshiono
Created September 5, 2016 04:59
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 takatoshiono/baa7528641b40c11a1ab3a557bd006a1 to your computer and use it in GitHub Desktop.
Save takatoshiono/baa7528641b40c11a1ab3a557bd006a1 to your computer and use it in GitHub Desktop.
A Tour of Go: Exercise Images, https://go-tour-jp.appspot.com/methods/25
package main
import "golang.org/x/tour/pic"
import "image"
import "image/color"
type Image struct {
width int
height int
}
func (img Image) ColorModel() color.Model {
return color.RGBAModel
}
func (img Image) Bounds() image.Rectangle {
return image.Rect(0, 0, img.width, img.height)
}
func (img Image) At(x, y int) color.Color {
return color.RGBA{uint8(x % 256), uint8(y % 256), 255, 255}
}
func main() {
m := Image{200, 200}
pic.ShowImage(m)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment