Graphics.Rotate

From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!
Method

Graphics.Rotate(angle As Double)

New in 2020r2

Supported for all project types and targets.

Rotates the drawing context by the specified angle (in radians) around the origin point (usually 0,0). This only affects subsequent drawing. Any drawing done before the Rotate method call is not rotated.


Method

Graphics.Rotate(angle As Double, x As Double, y As Double)

New in 2020r2

Supported for all project types and targets.

Rotates the drawing context at the x and y coordinates by the specified angle (in radians). This only affects subsequent drawing. Any drawing done before the Rotate method called is not rotated.

Notes

Use Translate to move the origin.

Support for Rotate in Desktop and Console applications was added in 2021r1.

When used in combination with Scale and/or Translate to draw into a PDFDocument, Rotate may behave differently than it does when drawing to normal Graphics object because the rotation is being handled by the PDF engine itself.

Sample Code

From within an MobileCanvas.Paint event handler:

// Rotate square in center of graphics area
Const Pi = 3.14159
g.Translate(g.Width / 2, g.Height / 2)
g.Rotate(Pi / 4) // 45 degrees or 1/8 of a circle
g.DrawingColor = Color.Blue
g.FillRectangle(10, 10, 50, 50)
// Rotate the entire drawing area around its center
// and draw a rectangle
Const Pi = 3.14159
g.Rotate(Pi / 4, g.Width / 2, g.Height / 2) // 45 degrees or 1/8 of a circle
g.DrawingColor = Color.Blue
g.FillRectangle(g.Width / 2 - 20, g.Height / 2 - 20, 20, 20)