Skip to content

Instantly share code, notes, and snippets.

@oldergod
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oldergod/01b26e77029c7b5c038a to your computer and use it in GitHub Desktop.
Save oldergod/01b26e77029c7b5c038a to your computer and use it in GitHub Desktop.
Tour of Go Image
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