Skip to content

Instantly share code, notes, and snippets.

@zainfathoni
Created April 11, 2017 03:11
Show Gist options
  • Save zainfathoni/533f8fd90f0f878c2e124f40baa99b4d to your computer and use it in GitHub Desktop.
Save zainfathoni/533f8fd90f0f878c2e124f40baa99b4d to your computer and use it in GitHub Desktop.
package main
import (
"golang.org/x/tour/pic"
"image"
"image/color"
)
type Image struct {
Width, Height int
}
func r(x, y int) uint8 {
return (uint8(x) + uint8(y)) / 2
}
func g(x, y int) uint8 {
return uint8(x) * uint8(y)
}
func b(x, y int) uint8 {
return uint8(x) ^ uint8(y)
}
func (img Image) ColorModel() color.Model {
return color.RGBAModel
}
func (img Image) Bounds() image.Rectangle {
return image.Rect(0, 0, img.Width, img.Height)
}
func (img Image) At(x, y int) color.Color {
return color.RGBA{r(x, y), g(x, y), b(x, y), 255}
}
func main() {
m := Image{100, 100}
pic.ShowImage(m)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment