Created
September 4, 2013 14:17
-
-
Save flc/6437570 to your computer and use it in GitHub Desktop.
A Tour of Go - Exercise: Images
http://tour.golang.org/#60
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" | |
"image/color" | |
) | |
type Image struct{ | |
width int | |
height int | |
} | |
func (img Image) ColorModel() color.Model { | |
return color.RGBAModel | |
} | |
func (img Image) Bounds() image.Rectangle { | |
return image.Rect(0, 0, img.width, img.height) | |
} | |
func (img Image) At(x, y int) color.Color { | |
img_func := func(x, y int) uint8 { | |
//return uint8(x*y) | |
//return uint8((x+y) / 2) | |
return uint8(x^y) | |
} | |
v := img_func(x, y) | |
return color.RGBA{v, v, 255, 255} | |
} | |
func main() { | |
m := Image{256, 64} | |
pic.ShowImage(m) | |
} |
krapie
commented
Dec 9, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment