Graphics draw_ellipse interface

This page explains the Graphics class draw_ellipse method interface.

What interface is this?

The draw_ellipse interface draws the vector ellipse graphics.

Basic usage

The draw_ellipse interface has the x, y, width, and height arguments. The x and y arguments are the ellipse center coordinates. The width and height arguments are the ellipse size. These sizes are twice the size of the radius.

import apysc as ap

ap.Stage(
    background_color=ap.Color("#333"),
    stage_width=325,
    stage_height=200,
    stage_elem_id="stage",
)

sprite: ap.Sprite = ap.Sprite()

# Set the cyan fill color and draw the ellipse.
sprite.graphics.begin_fill(color=ap.Color("#0af"))
sprite.graphics.draw_ellipse(x=125, y=100, width=150, height=100)

# Set the only dotted-line style and draw the ellipse.
sprite.graphics.begin_fill(color=ap.COLORLESS)
sprite.graphics.line_style(
    color=ap.Color("#fff"),
    thickness=3,
    dot_setting=ap.LineDotSetting(dot_size=3),
)
sprite.graphics.draw_ellipse(x=200, y=100, width=150, height=100)

ap.save_overall_html(dest_dir_path="graphics_draw_ellipse_basic_usage/")

Return value

The return value of the draw_ellipse interface is the instance of the Ellipse class.

It has basic interfaces (like the x or the width attributes) similar to the other graphics classes.

The following code example binds the click event handler. If you click the ellipse, the width and height become wider.

import apysc as ap


def on_ellipse_click(e: ap.MouseEvent[ap.Ellipse], options: dict) -> None:
    """
    The handler that the ellipse calls when clicked.

    Parameters
    ----------
    e : MouseEvent
        Event instance.
    options : dict
        Optional arguments dictionary.
    """
    ellipse: ap.Ellipse = e.this
    ellipse.width += 15
    ellipse.height += 10


ap.Stage(
    background_color=ap.Color("#333"),
    stage_width=250,
    stage_height=200,
    stage_elem_id="stage",
)

sprite: ap.Sprite = ap.Sprite()

sprite.graphics.begin_fill(color=ap.Color("#0af"))
ellipse: ap.Ellipse = sprite.graphics.draw_ellipse(x=125, y=100, width=150, height=100)
ellipse.click(on_ellipse_click)

ap.save_overall_html(dest_dir_path="graphics_draw_ellipse_return_value/")

draw_ellipse API

Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.

[Interface signature] draw_ellipse(self, *, x: Union[float, apysc._type.number.Number], y: Union[float, apysc._type.number.Number], width: Union[int, apysc._type.int.Int], height: Union[int, apysc._type.int.Int], variable_name_suffix: str = '') -> '_ellipse.Ellipse'


[Interface summary]

Draw an ellipse vector graphic.


[Parameters]

  • x: float or Number

    • X-coordinate of the ellipse center.

  • y: float or Number

    • Y-coordinate of the ellipse center.

  • width: Int or int

    • Ellipse width.

  • height: Int or int

    • Ellipse height.

  • variable_name_suffix: str, default “”

    • A JavaScript variable name suffix string. This setting is sometimes useful for JavaScript debugging.


[Returns]

  • ellipse: Ellipse

    • Created ellipse graphics instance.


[Examples]

>>> import apysc as ap
>>> stage: ap.Stage = ap.Stage()
>>> sprite: ap.Sprite = ap.Sprite()
>>> sprite.graphics.begin_fill(color=ap.Color("#0af"))
>>> ellipse: ap.Ellipse = sprite.graphics.draw_ellipse(
...     x=100, y=100, width=100, height=50
... )
>>> ellipse.x
Number(100.0)

>>> ellipse.y
Number(100.0)

>>> ellipse.width
Int(100)

>>> ellipse.height
Int(50)

>>> ellipse.fill_color
Color("#00aaff")