Created
March 29, 2022 04:22
-
-
Save anna-hope/cfdaa9f8cea6926ac9ea3464239fa737 to your computer and use it in GitHub Desktop.
Random Image in go
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 ( | |
"image" | |
"image/color" | |
"math/rand" | |
"time" | |
"golang.org/x/tour/pic" | |
) | |
type Image struct{} | |
func (img Image) ColorModel() color.Model { | |
return color.RGBAModel | |
} | |
func (img Image) Bounds() image.Rectangle { | |
return image.Rect(0, 0, 100, 100) | |
} | |
func (img Image) At(x, y int) color.Color { | |
rand.Seed(time.Now().UnixNano()) | |
v := uint8(x ^ y) | |
return color.RGBA{v, v, 255, 255} | |
} | |
func main() { | |
m := Image{} | |
pic.ShowImage(m) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment