holly molly
This commit is contained in:
87
letter/image.go
Normal file
87
letter/image.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package letter
|
||||
|
||||
import (
|
||||
"clock/imageutils"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
)
|
||||
|
||||
type Letter string
|
||||
|
||||
var Nums = []Letter{
|
||||
"111101111",
|
||||
"010010010",
|
||||
"110010011",
|
||||
"111011111",
|
||||
"101111001",
|
||||
"011010110",
|
||||
"001111111",
|
||||
"111001001",
|
||||
"011111111",
|
||||
"111111001",
|
||||
}
|
||||
|
||||
var Empty = Letter("000000000").Render()
|
||||
|
||||
func (l Letter) ColorModel() color.Model {
|
||||
return color.RGBAModel
|
||||
}
|
||||
|
||||
func (l Letter) Bounds() image.Rectangle {
|
||||
return image.Rect(0, 0, 3, 3)
|
||||
}
|
||||
|
||||
func (l Letter) At(x, y int) color.Color {
|
||||
target := l[x+y*3]
|
||||
if target != '1' {
|
||||
return color.Alpha{}
|
||||
}
|
||||
return color.Black
|
||||
}
|
||||
|
||||
func (l Letter) Render() image.Image {
|
||||
img := image.NewRGBA(l.Bounds())
|
||||
draw.Draw(img, l.Bounds(), image.White, image.ZP, draw.Src)
|
||||
draw.Draw(img, l.Bounds(), l, image.ZP, draw.Over)
|
||||
return img
|
||||
}
|
||||
|
||||
type blank struct {
|
||||
image.Image
|
||||
color.Color
|
||||
imageutils.Side
|
||||
}
|
||||
|
||||
func (b blank) ColorModel() color.Model { return b.Image.ColorModel() }
|
||||
|
||||
func (b blank) Bounds() image.Rectangle {
|
||||
rect := image.Rectangle{}
|
||||
switch b.Side {
|
||||
case imageutils.Left:
|
||||
fallthrough
|
||||
case imageutils.Right:
|
||||
rect = image.Rectangle{
|
||||
image.ZP,
|
||||
image.Point{
|
||||
1, b.Image.Bounds().Dy(),
|
||||
},
|
||||
}
|
||||
case imageutils.Up:
|
||||
fallthrough
|
||||
case imageutils.Down:
|
||||
rect = image.Rectangle{
|
||||
image.ZP,
|
||||
image.Point{
|
||||
b.Image.Bounds().Dx(), 1,
|
||||
},
|
||||
}
|
||||
}
|
||||
return rect
|
||||
}
|
||||
|
||||
func (b blank) At(x, y int) color.Color { return b.Color }
|
||||
|
||||
func Blank(img image.Image, clr color.Color, side imageutils.Side) image.Image {
|
||||
return imageutils.Concat(img, blank{img, clr, side}, side)
|
||||
}
|
Reference in New Issue
Block a user