Created
December 25, 2013 02:04
-
-
Save kaipakartik/8119598 to your computer and use it in GitHub Desktop.
Exercise: Images Remember the picture generator you wrote earlier? Let's write another one, but this time it will return an implementation of image.Image instead of a slice of data.
This file contains hidden or 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/color" | |
"image" | |
) | |
type Image struct{ | |
width, height int | |
colr uint8 | |
} | |
func (i Image) ColorModel() color.Model { | |
return color.RGBAModel | |
} | |
func(i Image) Bounds() image.Rectangle { | |
return image.Rect(0, 0, i.width, i.height) | |
} | |
func (i Image) At(x, y int) color.Color { | |
return color.RGBA{i.colr+uint8(x), i.colr+uint8(y), 255, 255} | |
} | |
func main() { | |
m := Image{100, 100, 128} | |
pic.ShowImage(m) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment