Skip to content

Instantly share code, notes, and snippets.

@anna-hope
Created March 29, 2022 04:22
Show Gist options
  • Save anna-hope/cfdaa9f8cea6926ac9ea3464239fa737 to your computer and use it in GitHub Desktop.
Save anna-hope/cfdaa9f8cea6926ac9ea3464239fa737 to your computer and use it in GitHub Desktop.
Random Image in go
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