Skip to content

Instantly share code, notes, and snippets.

@danimal141
Created October 10, 2016 13:33
Show Gist options
  • Save danimal141/a42f25f908a0402b7c8cc3eb6aac76aa to your computer and use it in GitHub Desktop.
Save danimal141/a42f25f908a0402b7c8cc3eb6aac76aa to your computer and use it in GitHub Desktop.
A Tour of Go Exercise: Images
package main
import (
"golang.org/x/tour/pic"
"image"
"image/color"
)
type Image struct{
width int
height int
}
func (i Image) Bounds() image.Rectangle {
return image.Rect(0, 0, i.width, i.height)
}
func (i Image) ColorModel() color.Model {
return color.RGBAModel
}
func (i 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