来自golang tour 练习 https://tour.go-zh.org/methods/16
package main import "golang.org/x/tour/pic" import "image" import "image/color" type Image struct{ x, y, width, height int } func (im Image) ColorModel() color.Model { return color.RGBAModel } func (im Image) Bounds() image.Rectangle { return image.Rect(im.x, im.y, im.width, im.height) } func (im Image) At(x, y int) color.Color { return color.RGBA{uint8((x^y)/2), uint8((x+y)/2), 255, 255} } func main() { m := Image{0,0, 200, 200} pic.ShowImage(m) }
时间: 2024-10-04 00:54:51