Tuesday, December 08, 2015

Golang Exercise: Images

code:

package main

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


type Image struct{}

func (p Image) Bounds() image.Rectangle {
 return image.Rect(0, 0, 256, 256)
}


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


func (m Image) At(x, y int) color.Color {
 v := uint8(x * y)
 return color.RGBA{v, v, 255, 255}
}


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


Ref:

http://tour.golang.org/methods/16

No comments: