Skip to content

Instantly share code, notes, and snippets.

@uraimo
Created June 6, 2013 12:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uraimo/5721070 to your computer and use it in GitHub Desktop.
Save uraimo/5721070 to your computer and use it in GitHub Desktop.
A Tour of Go #59: Images Exercise
package main
import (
"code.google.com/p/go-tour/pic"
"image"
"image/color"
)
func Sqrt(f int) int {
var z int = 1
for i:=0;i<5;i++ {
z=z-(z*z-f)/(2*z)
}
return z
}
type Image struct{
width int
length int
}
func (i Image) Bounds() image.Rectangle {
return image.Rectangle{image.Point{0,0}, image.Point{i.width,i.length}}
}
func (i Image) At(x, y int) color.Color {
x1 := Sqrt(x*y)
return color.RGBA{uint8(x),uint8(y)*uint8(x1),255,255}
}
func (i Image) ColorModel() color.Model {
return color.RGBAModel
}
func main() {
m := Image{200,200}
pic.ShowImage(m)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment