package main
import (
"image"
"image/color"
"image/draw"
)
type img struct {
*image.RGBA
}
func Image(opt Options) image.Image {
im := img{image.NewRGBA(image.Rectangle{image.Point{}, image.Point{opt.Width, opt.Height}})}
switch opt.Pattern {
case "plain":
draw.Draw(im, im.Bounds(), image.NewUniform(opt.Colors[0]), image.Point{}, draw.Src)
case "diagonal":
h, w := float64(im.Bounds().Max.Y-im.Bounds().Min.Y), float64(im.Bounds().Max.X-im.Bounds().Min.X)
draw.Draw(im, im.Bounds(), image.NewUniform(opt.Colors[0]), image.Point{}, draw.Src)
draw.DrawMask(im, im.Bounds(), image.NewUniform(opt.Colors[1]), image.Point{}, &diagonal{im, h, w}, image.Point{}, draw.Over)
}
return im
}
type diagonal struct {
image.Image
h, w float64
}
func (im *diagonal) At(x, y int) color.Color {
if float64(y)+0.5 < im.h-(im.h/im.w)*float64(x) {
return color.Alpha{}
}
return color.Alpha{0xff}
}