Ellipse

Description

The ellipse() function draws an ellipse on the canvas. When the width and height are equal, it creates a perfect circle. The ellipse is drawn centered at the specified (x,y) coordinates.

Syntax

// Using positional parameters
ellipse(x, y, width, height)

// Using named parameters
ellipse(x: Float, y: Float, width: Float, height: Float)

Parameters

x

The x-coordinate of the ellipse's center

y

The y-coordinate of the ellipse's center

width

The width (horizontal diameter) of the ellipse

height

The height (vertical diameter) of the ellipse

Example

// Draw an ellipse at (100, 100) with width 200 and height 150
ellipse(100, 100, 200, 150)

// Draw a circle using named parameters (width equals height)
ellipse(x: 300, y: 300, width: 100, height: 100)

Notes

  • The ellipse is drawn centered at the specified (x,y) coordinates
  • When width equals height, the result is a perfect circle
  • The stroke width is set to 3 by default
  • The fill and stroke colors can be customized using the current fill and stroke settings