Graphics draw_round_rect interface

This page explains the Graphics class draw_round_rect method interface.

What interface is this?

draw_round_rect interface draws vector rounded rectangle graphics.

Basic usage

draw_round_rect interface has x, y, width, and height arguments. x and y are rectangle coordinates settings, and width and height determine rectangle size.

This interface also has ellipse_width and ellipse_height arguments to set the round size to the rectangle corners.

import apysc as ap

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

sprite: ap.Sprite = ap.Sprite()
sprite.graphics.begin_fill(color=ap.Color("#0af"))

# Set 10-pixel ellipse size and draw the rectangle.
sprite.graphics.draw_round_rect(
    x=50, y=50, width=50, height=50, ellipse_width=10, ellipse_height=10
)

# Set 20-pixel ellipse size and draw the rectangle.
sprite.graphics.draw_round_rect(
    x=150, y=50, width=50, height=50, ellipse_width=20, ellipse_height=20
)

# Set 5-pixel ellipse width and 20-pixel ellipse height and
# draw the rectangle.
sprite.graphics.draw_round_rect(
    x=250, y=50, width=50, height=50, ellipse_width=5, ellipse_height=20
)

ap.save_overall_html(dest_dir_path="graphics_draw_round_rect_basic_usage/")

Return value

draw_round_rect interface will return the Rectangle instance, the same as the draw_rect interface.

The Rectangle instance has the ellipse_width attribute and ellipse_height to change the rectangle’s round size.

import apysc as ap

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

sprite: ap.Sprite = ap.Sprite()
sprite.graphics.begin_fill(color=ap.Color("#0af"))

rectangle: ap.Rectangle = sprite.graphics.draw_round_rect(
    x=50, y=50, width=50, height=50, ellipse_width=10, ellipse_height=10
)

# You can update the ellipse_width and ellipse_height
# attributes dynamically.
rectangle.ellipse_width = ap.Int(20)

ap.save_overall_html(dest_dir_path="graphics_draw_round_rect_return_value/")

draw_round_rect 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_round_rect(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], ellipse_width: Union[int, apysc._type.int.Int], ellipse_height: Union[int, apysc._type.int.Int], variable_name_suffix: str = '') -> apysc._display.rectangle.Rectangle


[Interface summary]

Draw a rounded rectangle vector graphics.


[Parameters]

  • x: float or Number

    • X-coordinate to start drawing.

  • y: float or Number

    • Y-coordinate to start drawing.

  • width: Int or int

    • Rectangle width.

  • height: Int or int

    • Rectangle height.

  • ellipse_width: Int or int

    • Ellipse width of the rectangle corner.

  • ellipse_height: Int or int

    • Ellipse height of the rectangle corner.

  • variable_name_suffix: str, default “”

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


[Returns]

  • rectangle: Rectangle

    • Created rectangle.


[Examples]

>>> import apysc as ap
>>> stage: ap.Stage = ap.Stage()
>>> sprite: ap.Sprite = ap.Sprite()
>>> sprite.graphics.begin_fill(color=ap.Color("#0af"))
>>> round_rect: ap.Rectangle = sprite.graphics.draw_round_rect(
...     x=50, y=50, width=50, height=50, ellipse_width=10, ellipse_height=15
... )
>>> round_rect.ellipse_width
Int(10)

>>> round_rect.ellipse_height
Int(15)