Created
June 6, 2013 12:15
-
-
Save uraimo/5721070 to your computer and use it in GitHub Desktop.
A Tour of Go #59: Images Exercise
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" | |
) | |
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