image "fun"

This commit is contained in:
Ryan Cavicchioni 2020-02-10 19:56:18 -06:00
parent 7ee04a1864
commit 170df84749
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
2 changed files with 39 additions and 0 deletions

27
exercise-images.go Normal file
View File

@ -0,0 +1,27 @@
package main
import (
"image"
"image/color"
"golang.org/x/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, 100, 100)
}
func (i Image) At(x, y int) color.Color {
v := uint8(x) ^ uint8(y)
return color.RGBA{v, v, 255, 255}
}
func main() {
m := Image{}
pic.ShowImage(m)
}

12
images.go Normal file
View File

@ -0,0 +1,12 @@
package main
import (
"fmt"
"image"
)
func main() {
m := image.NewRGBA(image.Rect(0, 0, 100, 100))
fmt.Println(m.Bounds())
fmt.Println(m.At(0, 0).RGBA())
}