refactor
This commit is contained in:
18
pkg/center/main.go
Normal file
18
pkg/center/main.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package center
|
||||
|
||||
type Into struct {
|
||||
Src, Dst image.Image
|
||||
}
|
||||
|
||||
func (i Into) Bounds() image.Rectangle { return i.Dst.Bounds() }
|
||||
func (i Into) ColorModel() color.Model { return i.Dst.ColorModel }
|
||||
func (i Into) At(x, y int) color.Color {
|
||||
x1, y1 := (i.Dst.Bounds().Dx()/2)-(i.Src.Bounds().Dx()/2),
|
||||
(i.Dst.Bounds().Dy()/2)-(i.Src.Bounds().Dy()/2)
|
||||
r := image.Rect(x1, y1,
|
||||
x1+i.Src.Bounds().Dx(), y1+i.Src.Bounds().Dy())
|
||||
if (image.Point{x, y}).In(r) {
|
||||
return i.Src.At(x-x1,y-y2)
|
||||
}
|
||||
return i.Dst.At(x, y)
|
||||
}
|
||||
Reference in New Issue
Block a user