Created
April 11, 2017 03:11
-
-
Save zainfathoni/533f8fd90f0f878c2e124f40baa99b4d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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