27 lines
651 B
Go
27 lines
651 B
Go
package ggfx
|
|
|
|
import "image"
|
|
|
|
type plottingContext[T any] struct {
|
|
Image[T]
|
|
color T
|
|
weight int
|
|
offset int
|
|
}
|
|
|
|
func (context plottingContext[T]) square (center image.Point) (square image.Rectangle) {
|
|
return image.Rect(0, 0, context.weight, context.weight).
|
|
Sub(image.Pt(context.weight / 2, context.weight / 2)).
|
|
Add(center).
|
|
Intersect(context.Rect)
|
|
}
|
|
|
|
func (context plottingContext[T]) plot (center image.Point) {
|
|
square := context.square(center)
|
|
for y := square.Min.Y; y < square.Max.Y; y ++ {
|
|
for x := square.Min.X; x < square.Max.X; x ++ {
|
|
index := context.PixOffset(x, y) + context.offset
|
|
context.Pix[index] = context.color
|
|
}}
|
|
}
|