# Rotating a sprite 90 degrees

**URL:** <https://forum.makecode.com/t/rotating-a-sprite-90-degrees/36750>\
**Category:** Help\
**Created:** [May 17, 2025, 11:47pm UTC](https://forum.makecode.com/t/rotating-a-sprite-90-degrees/36750 "2025-05-17T23:47:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![slush](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@slush](https://forum.makecode.com/u/slush)\
**Post date:** [May 17, 2025, 11:47pm UTC](https://forum.makecode.com/t/rotating-a-sprite-90-degrees/36750/1 "2025-05-17T23:47:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![randomuser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/randomuser/32/32505_2.png) [@randomuser](https://forum.makecode.com/u/randomuser)\
**Post date:** [May 19, 2025, 1:41am UTC](https://forum.makecode.com/t/rotating-a-sprite-90-degrees/36750/2 "2025-05-19T01:41:25Z")

</div>

[Image transformation extension](https://forum.makecode.com/t/having-a-blast-with-makecode-arcade/59/6) is the most popular way to do this!

---

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [May 19, 2025, 1:43am UTC](https://forum.makecode.com/t/rotating-a-sprite-90-degrees/36750/3 "2025-05-19T01:43:53Z")

</div>

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:

```auto
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:

 ![IMG_8814](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/f/f/ff478db48cd91853bd6e862d1aece4046de3e4d3.jpeg)
