Skip to content

Instantly share code, notes, and snippets.

@evandertino
Created April 4, 2015 18:24
Show Gist options
  • Select an option

  • Save evandertino/c051f6e130222ce829aa to your computer and use it in GitHub Desktop.

Select an option

Save evandertino/c051f6e130222ce829aa to your computer and use it in GitHub Desktop.
Go Exercise: Images - http://tour.golang.org/methods/16
package main
import (
"golang.org/x/tour/pic"
"image"
"image/color"
)
type Image struct {
Width, Height int
color uint8
}
func (this *Image) ColorModel() color.Model {
return color.RGBAModel
}
func (this *Image) Bounds() image.Rectangle {
return image.Rect(0, 0, this.Width, this.Height)
}
func (this *Image) At(x, y int) color.Color {
return color.RGBA{this.color + uint8(x), this.color + 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