Added some utility functions to pattern

This commit is contained in:
Sasha Koshka 2023-02-23 15:00:44 -05:00
parent c7e44633b1
commit 0ba3c982c4

View File

@ -14,3 +14,28 @@ type Pattern interface {
// destination before passing it to Draw().
Draw (destination canvas.Canvas, clip image.Rectangle)
}
// Draw lets you use several clipping rectangles to draw a pattern.
func Draw (
destination canvas.Canvas,
source Pattern,
clips ...image.Rectangle,
) {
for _, clip := range clips {
source.Draw(destination, clip)
}
}
// DrawBounds is like Draw, but lets you specify an overall bounding rectangle
// for the pattern. The destination is cut to this rectangle.
func DrawBounds (
destination canvas.Canvas,
bounds image.Rectangle,
source Pattern,
clips ...image.Rectangle,
) {
cut := canvas.Cut(destination, bounds)
for _, clip := range clips {
source.Draw(cut, clip)
}
}