Skip to content

Instantly share code, notes, and snippets.

@flc
Created September 4, 2013 14:17
Show Gist options
  • Save flc/6437570 to your computer and use it in GitHub Desktop.
Save flc/6437570 to your computer and use it in GitHub Desktop.
A Tour of Go - Exercise: Images http://tour.golang.org/#60
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
Copy link

krapie commented Dec 9, 2022

package main

import (
	"golang.org/x/tour/pic"
	"image"
	"image/color"
)

type Image struct {
	width, height int
}

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{interpretCoordinate(x,y),interpretCoordinate(x,y), 255, 255}
}

func interpretCoordinate(x, y int) uint8 {
	n := x^y
	
	return uint8(n)
}

func main() {
	m := Image{100, 100}
	pic.ShowImage(m)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment