Skip to content

Instantly share code, notes, and snippets.

@jasonbot
Created April 13, 2022 18:11
Show Gist options
  • Save jasonbot/47f6e2c7b1ebde9810edb6f0f151d5ca to your computer and use it in GitHub Desktop.
Save jasonbot/47f6e2c7b1ebde9810edb6f0f151d5ca to your computer and use it in GitHub Desktop.
func RotatedImage(i *ebiten.Image, rotation float64) *ebiten.Image {
if i == nil {
return i
}
w, h := i.Size()
maxDim := int(math.Hypot(float64(w), float64(h)))
newimage := ebiten.NewImage(maxDim, maxDim)
op := ebiten.DrawImageOptions{}
op.GeoM.Translate(-float64(w/2), -float64(h/2))
op.GeoM.Rotate(rotation)
op.GeoM.Translate(float64(maxDim/2), float64(maxDim/2))
newimage.DrawImage(i, &op)
return newimage
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment