This is a creation in Article, where the information may have evolved or changed.
Remember The picture generator you wrote earlier? Let's write another one, but this time it would return an implementation of image.Image
instead of a slice of data.
Define your own Image
type, implement the necessary methods, and call pic.ShowImage
.
Bounds
Should return a image.Rectangle
, like image.Rect(0, 0, w, h)
.
ColorModel
should return color.RGBAModel
.
At
should return a color; The value of the last picture generator corresponds into this one v
color.RGBA{v, v, 255, 255}
.
package main
Import (
"image"
"Image/color"
"Tour/pic"
)
type Image struct{}
func (i *image) ColorModel () Color. Model {
return color. Rgbamodel
}
func (i *image) Bounds () Image. Rectangle {
return image. Rect (0, 0, ())
}
func (i *image) at (x, y int) color. Color {
V: = (uint8) (x^y)
return Color. Rgba{v, V, 255, 255}
}
Func main () {
m: = &image{}
Span style= "White-space:pre" > pic. ShowImage (M)
}