edbit/application/canvas.go

30 lines
515 B
Go

package application
import (
"image"
"math"
"github.com/hajimehoshi/ebiten/v2"
)
type canvas struct {
w, h int
img *ebiten.Image
scale float64
}
func NewCanvas(w, h int) *canvas {
return &canvas{
w: w,
h: h,
img: ebiten.NewImage(w, h),
scale: 1,
}
}
func (c *canvas) pixelScreenRect(x, y int) image.Rectangle {
return image.Rect(int(math.Floor(float64(x)*c.scale)), int(math.Floor(float64(y)*c.scale)), int(math.Ceil(float64(x+1)*c.scale)), int(math.Ceil(float64(y+1)*c.scale)))
}