Skip to content

Instantly share code, notes, and snippets.

@poppen
Created November 23, 2013 04:23
Show Gist options
  • Select an option

  • Save poppen/7610757 to your computer and use it in GitHub Desktop.

Select an option

Save poppen/7610757 to your computer and use it in GitHub Desktop.
An answer of the exercise: Images on a tour of go
package main
import (
"code.google.com/p/go-tour/pic"
"image"
"image/color"
)
type Image struct {
Width, Height int
Color uint8
}
func (i *Image) ColorModel() color.Model {
return color.RGBAModel
}
func (i *Image) Bounds() image.Rectangle {
return image.Rect(0, 0, i.Width, i.Height)
}
func (i *Image) At(x, y int) color.Color {
return color.RGBA{i.Color, i.Color, 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