golang官方练习: image

golang官方练习: image




[root@sltvb7v2wy3 jia_methods]# cat  exercise_images.go

package main

import (
    "golang.org/x/tour/pic"
    "image"
    "image/color"
)

type Image struct{
    w int
    h int

}

func (self Image) ColorModel() color.Model {
    return color.RGBAModel
}

func (self Image) Bounds() image.Rectangle {
    return image.Rect(0, 0, self.w, self.h)
}

func (self Image) At(x, y int) color.Color {
    r := (uint8)((float64)(x) / (float64)(self.w) * 255.0)
    g := (uint8)((float64)(y) / (float64)(self.h) * 255.0)
    b := (uint8)((float64)(x * y) / (float64)(self.w * self.h) * 255.0)
    return color.RGBA{r, g, b, 255}
}

func main() {
    m := Image{255, 255}
    pic.ShowImage(m)
}






[root@sltvb7v2wy3 jia_methods]# gor  exercise_images.go
exercise_images.go:4:5: missing go.sum entry for module providing package golang.org/x/tour/pic; to add:
        go mod download golang.org/x/tour


[root@sltvb7v2wy3 jia_methods]# go mod download golang.org/x/tour
[root@sltvb7v2wy3 jia_methods]# gor  exercise_images.go
go: updates to go.mod needed; to update it:
        go mod tidy
[root@sltvb7v2wy3 jia_methods]#  go mod tidy
[root@sltvb7v2wy3 jia_methods]# gor  exercise_images.go
...


[root@sltvb7v2wy3 jia_methods]# cat go.sum |grep tour
github.com/Go-zh/tour v0.0.0-20210601082505-f4baf0dba327 h1:rAJE7urEj+91TDJ2yNpprGSUtBdzQEJzZRac6SOvUS0=
github.com/Go-zh/tour v0.0.0-20210601082505-f4baf0dba327/go.mod h1:Kw1ejiuuAKSZoUSHHYCTIPGGgOfEge3eiwoFzQ9j8Kw=
golang.org/x/tour v0.0.0-20190313211959-7de0bd1d74c6 h1:Lc7Ee4UuWUQKX4mkhJHgYIKyIzTmhEk8PZnvZ73gWuM=
golang.org/x/tour v0.0.0-20190313211959-7de0bd1d74c6/go.mod h1:qMugOFWX59KzC8Nx7f2uvXxKxAqJfi1J6ZUHAWKnrRA=



你可能感兴趣的:(golang官方练习: image)