Created
October 28, 2020 00:34
-
-
Save steph9009/39090c2042745c6c120ed5f65f9f771d to your computer and use it in GitHub Desktop.
Exercise: Images https://tour.golang.org/methods/25
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"image" | |
"image/color" | |
"golang.org/x/tour/pic" | |
) | |
type Image struct{} | |
// ColorModel returns the Image's color model. | |
func (i Image) ColorModel() color.Model { | |
return color.RGBAModel | |
} | |
// Bounds returns the domain for which At can return non-zero color. | |
// The bounds do not necessarily contain the point (0, 0). | |
func (i Image) Bounds() image.Rectangle { | |
return image.Rect(0, 0, 666, 333) | |
} | |
// At returns the color of the pixel at (x, y). | |
// At(Bounds().Min.X, Bounds().Min.Y) returns the upper-left pixel of the grid. | |
// At(Bounds().Max.X-1, Bounds().Max.Y-1) returns the lower-right one. | |
func (i Image) At(x, y int) color.Color { | |
a, b, c := uint8(x+y)/2, uint8(x*y), uint8(x^y) | |
return color.RGBA{c, a, b, 255} | |
} | |
func main() { | |
m := Image{} | |
pic.ShowImage(m) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment