Skip to content

Instantly share code, notes, and snippets.

@kaipakartik
Created December 25, 2013 02:04
Show Gist options
  • Save kaipakartik/8119598 to your computer and use it in GitHub Desktop.
Save kaipakartik/8119598 to your computer and use it in GitHub Desktop.
Exercise: Images Remember the picture generator you wrote earlier? Let's write another one, but this time it will return an implementation of image.Image instead of a slice of data.
package main
import (
"code.google.com/p/go-tour/pic"
"image/color"
"image"
)
type Image struct{
width, height int
colr 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.colr+uint8(x), i.colr+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