Last active
August 29, 2015 14:06
-
-
Save oldergod/01b26e77029c7b5c038a to your computer and use it in GitHub Desktop.
Tour of Go Image
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" | |
) | |
const DIM = 1024 | |
func Red(i, j int) uint8 { | |
var v int | |
if i != 0 && j != 0 { | |
v = (i % j) & (j % i) | |
} else { | |
v = 0 | |
} | |
return uint8(v) | |
} | |
func Green(i, j int) uint8 { | |
var v int | |
if i != 0 && j != 0 { | |
v = (i % j) + (j % i) | |
} else { | |
v = 0 | |
} | |
return uint8(v) | |
} | |
func Blue(i, j int) uint8 { | |
var v int | |
if i != 0 && j != 0 { | |
v = (i % j) | (j % i) | |
} else { | |
v = 0 | |
} | |
return uint8(v) | |
} | |
type Image struct{} | |
func (i *Image) ColorModel() color.Model { | |
return color.RGBAModel | |
} | |
func (i *Image) Bounds() image.Rectangle { | |
return image.Rect(0, 0, DIM, DIM) | |
} | |
func (img *Image) At(i, j int) color.Color { | |
return color.RGBA{Red(i, j), Green(i, j), Blue(i, j), 255} | |
} | |
func main() { | |
m := Image{} | |
var img image.Image | |
img = &m | |
pic.ShowImage(img) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment