Skip to content

Instantly share code, notes, and snippets.

@rndD
Created December 28, 2014 17:08
Show Gist options
  • Save rndD/bc466b2117020802af91 to your computer and use it in GitHub Desktop.
Save rndD/bc466b2117020802af91 to your computer and use it in GitHub Desktop.
A tour of GO: Exercise: Images
package main
import (
"code.google.com/p/go-tour/pic"
"image"
"image/color"
)
type Image struct{}
// ColorModel returns the Image's color model.
func (i Image) ColorModel() color.Model {
return color.RGBAModel
}
// Bounds returns the domain for which At can return non-zero color.
// The bounds do not necessarily contain the point (0, 0).
func (i Image) Bounds() image.Rectangle {
return image.Rect(0, 0, 255, 255)
}
// At returns the color of the pixel at (x, y).
// At(Bounds().Min.X, Bounds().Min.Y) returns the upper-left pixel of the grid.
// At(Bounds().Max.X-1, Bounds().Max.Y-1) returns the lower-right one.
func (i Image) At(x, y int) color.Color {
return color.RGBA{uint8(x + y), 255, 3, uint8(x)}
}
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