Created
April 13, 2022 18:11
-
-
Save jasonbot/47f6e2c7b1ebde9810edb6f0f151d5ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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