drawRotatedImage

This is the same as the other drawImage function, except that it takes an angle, and the image will be rotated by this angle when drawn.

Images are always rotated around their centre, rotations are performed in a clockwise direction, and all angles are in radians.

drawRotatedImage( image, angle, x, y, isCentred=false )

Draws the image at the x and y location given, and rotated by the angle. If 'isCentred' is true, then the x and y refer to the images centre, and otherwise it will drawn from the top-left corner.

croc = new Image( 'croc.png' )

drawRotatedImage( croc, 30.toRadians(), 10, 10 )
drawRotatedImage( croc, -45.toRadians(), 100, 100, true )

drawRotatedImage( image, angle, x, y, width, height, isCentred=false )

Draws the rotated image, but scaled to the width and height given. If 'isCentred' is true, then the image is centred around the 'x' and 'y' location, based on 'width' and 'height'.

croc = new Image( 'croc.png' )
angle = 30.toRadians()

// draw at double the size
drawRotatedImage( croc, angle, 10, 10,
        croc.getWidth()*2, croc.getHeight()*2 )

// draw at a massive size!
drawRotatedImage( croc, angle, 100, 10, 200, 200, false )

drawRotatedImage( image, angle, srcX, srcY, srcWidth, srcHeight, x, y, isCentred=false )

'srcX', 'srcY', 'srcWidth' and 'srcHeight' describe a rectangle found on the given image. This section of the image is drawn to the screen, at the 'x' and 'y' location, and rotated by 'angle'.

'isCentred' only alters where the image is drawn around 'x' and 'y', it has no bearing on the src parameters.

spries = new Image( 'sprites.png' )

// draw a 32x32 section of 'sprites' to the screen
drawRotatedImage( sprites, 45.toRadians(), 0, 0, 32, 32, x, y )

drawRotatedImage( image, angle, srcX, srcY, srcWidth, srcHeight, x, y, width, height, isCentred=false )

The same as the previous 'drawRotatedImage', only 'width' and 'height' parameters are added to allow you to scale the src section of the image, when it is drawn.

spries = new Image( 'sprites.png' )

// Draw a 32x32 section of 'sprites' to the screen,
// rotated, and at double the size.
drawRotatedImage( sprites, 130.toRadians(),
        0, 0, 32, 32, x, y, 64, 64 )

Screen of Crocs

This fills the screen with rotated croc images. It can be used in the Sandbox.

croc = new Image( 'croc.png' )

onEachFrame() do
    fill( :black )
    
    // Draw a 32x32 section of 'sprites' to the screen,
    // but at double the height.
    10.times() do |y|
        16.times() do |x|
            if (x+y) % 2 == 0
                angle =   30.toRadians()
            else
                angle = - 30 .toRadians()
            end
            
            drawRotatedImage( croc, angle, -2+x*40, 3+y*40 )
        end
    end
end

See also

Image Class - setColor - drawImage