Skip to content

Instantly share code, notes, and snippets.

@steph9009
Created October 28, 2020 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steph9009/39090c2042745c6c120ed5f65f9f771d to your computer and use it in GitHub Desktop.
Save steph9009/39090c2042745c6c120ed5f65f9f771d to your computer and use it in GitHub Desktop.
package main
import (
"image"
"image/color"
"golang.org/x/tour/pic"
)
type Image struct{}
// ColorModel returns the Image's color model.
func (i Image) ColorModel() color.Model {
return color.RGBAModel
}
// Bounds returns the domain for which At can return non-zero color.
// The bounds do not necessarily contain the point (0, 0).
func (i Image) Bounds() image.Rectangle {
return image.Rect(0, 0, 666, 333)
}
// At returns the color of the pixel at (x, y).
// At(Bounds().Min.X, Bounds().Min.Y) returns the upper-left pixel of the grid.
// At(Bounds().Max.X-1, Bounds().Max.Y-1) returns the lower-right one.
func (i Image) At(x, y int) color.Color {
a, b, c := uint8(x+y)/2, uint8(x*y), uint8(x^y)
return color.RGBA{c, a, b, 255}
}
func main() {
m := Image{}
pic.ShowImage(m)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment