Best way to draw an ellipse

In processing there is an ellipse primitive: https://processing.org/reference/ellipse_.html
but it looks like openrndr only has the “circle” primitive.
what would be the best way to achieve an ellipse? I am guessing it can be done with the scale transform?

Hi! Yes scaling is one way. Not sure what’s the “best way”, but this works:

drawer.pushProjection()
drawer.translate(x, y)
drawer.scale(xScale, yScale)
drawer.circle(0.0, 0.0, radius)
drawer.popProjection()

If you set radius to 50.0 for example, xScale to 1.0 and yScale to 0.5, then the horizontal radius is 50.0 and the vertical one 25.0, so it looks like a resting egg :slight_smile:

1 Like

I figured out another way to create an ellipse shape:

val t = transform { scale(0.5, 1.0, 1.0) }
val oval = Circle(Vector2.ZERO, 100.0).shape.transform(t)

This could be applied also to shapes loaded from SVG, and not limited to scale but you can also rotate and translate.

I guess it’s not ideal to apply those transformations in real time, but works if you prepare a bunch of shapes when the program starts.

For real time you can use transform {} applied to the view matrix like shown at the bottom of https://guide.openrndr.org/#/05_Drawing_and_transformations/C00_Transformations?id=projection-matrix (See drawer.view *= transform).