Rotating a sprite 90 degrees

I just want a quick script that rotates a sprite 90 degrees. I have already set up 2 images, one for orthogonal facing directions and the other for diagonal.

No, I don’t fancy rotating it precisely to this extent like 1 degree, I just want to rotate it 90 degrees for 8 directions.

2 Likes

Image transformation extension is the most popular way to do this!

2 Likes

There are built in functions for this already, at least for images. I could probably make another mini extension like I did for the person who wanted image scaling, but idk. I think I’m gonna make a giant extension that adds as many single-function Java features to blocks as possible. In the mean time, you can make such a function yourself! Really, what you need is something that loops through every pixel in an image and flips the X and Y. For example, in sudo code something like:

Function rotateImage90 (image) {

     Set rotatedImage ( create image with width (image[height]) height (image[width]) )

     For (index) from 0 to (image[height] - 1) {

          For (index2) from 0 to (image[width] - 1) {
               
                (rotatedImage) set pixel at (index2) ((image[height] - 1) - index) to ( (image) get color at (index) (index2) )

          }
     }
     
     Return (rotatedImage)
}

The important part is that “index” and “index2” are flipped when setting vs getting the pixel, and the height is made to go backwards when setting the pixel, which results in a flip over the line y=-x and then a flip over the y axis. This results in a pixel that’s, say, top right in the source image (“image”) getting put in the bottom right:

3 Likes