Created
March 10, 2021 11:24
-
-
Save m99coder/6b148989cea3501c835fc3c95f6990a8 to your computer and use it in GitHub Desktop.
Image interface
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 { | |
w, h int | |
} | |
func (i Image) ColorModel() color.Model { | |
return color.RGBAModel | |
} | |
func (i Image) Bounds() image.Rectangle { | |
return image.Rect(0, 0, i.w, i.h) | |
} | |
func (i Image) At(x, y int) color.Color { | |
v := uint8(x ^ y) | |
return color.RGBA{v, v, 255, 255} | |
} | |
func main() { | |
m := Image{256, 256} | |
pic.ShowImage(m) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment