Created
April 13, 2013 13:19
-
-
Save royling/563b7238c005293fa8b0 to your computer and use it in GitHub Desktop.
Define your own Image type, implement the necessary methods, and call pic.ShowImage. 1) Bounds should return a image.Rectangle, like image.Rect(0, 0, w, h). 2) ColorModel should return color.RGBAModel. 3) At should return a color; the value v in the last picture generator corresponds to color.RGBA{v, v, 255, 255} in this one.
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 ( | |
"code.google.com/p/go-tour/pic" | |
"image" | |
"image/color" | |
) | |
type Image struct{ | |
dx, dy int | |
col func(x, y int) uint8 | |
} | |
func (img *Image) ColorModel() color.Model { | |
return color.RGBAModel | |
} | |
func (img *Image) Bounds() image.Rectangle { | |
return image.Rect(0, 0, img.dx, img.dy) | |
} | |
func (img *Image) At(x, y int) color.Color { | |
col := img.col(x, y) | |
return color.RGBA{col, col, 255, 255} | |
} | |
func main() { | |
m := &Image{ | |
dx: 255, | |
dy: 255, | |
col: func(x, y int) uint8 { | |
return uint8(x^y) | |
}, | |
} | |
pic.ShowImage(m) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment