DisplayObject and GraphicsBase classes base properties abstract

This page explains the DisplayObject and GraphicsBase classes’ each property (such as the x, visible) abstract.

What apysc can do in its properties

  • You can get/set each property value, such as the x, y, visible.

x and y properties

The x and y properties can get/set the x and y coordinates.

Display the code block:
from typing_extensions import TypedDict

import apysc as ap


class RectOptions(TypedDict):
    rectangle: ap.Rectangle
    direction: ap.Int


def on_timer(e: ap.TimerEvent, options: RectOptions) -> None:
    """
    The handler that the timer calls.

    Parameters
    ----------
    e : ap.TimerEvent
        Event instance.
    options : RectOptions
        Optional arguments dictionary.
    """
    rectangle: ap.Rectangle = options["rectangle"]
    direction: ap.Int = options["direction"]
    rectangle.x += direction
    rectangle.y += direction

    with ap.If(rectangle.x >= 100):
        direction.value = -1
        ap.Return()

    with ap.If(rectangle.x <= 50):
        direction.value = 1
        ap.Return()


ap.Stage(
    background_color=ap.Color("#333"),
    stage_width=200,
    stage_height=200,
    stage_elem_id="stage",
)
sprite: ap.Sprite = ap.Sprite()
sprite.graphics.begin_fill(color=ap.Color("#0af"))
rectangle: ap.Rectangle = sprite.graphics.draw_rect(x=50, y=50, width=50, height=50)

direction: ap.Int = ap.Int(1)
options: RectOptions = {"rectangle": rectangle, "direction": direction}
ap.Timer(on_timer, delay=ap.FPS.FPS_60, options=options).start()

ap.save_overall_html(dest_dir_path="do_and_graphics_base_prop_abstract_x_and_y/")

For more details, please see the following:

visible property

The visible property can get/set the visibility of an object.

Display the code block:
from typing_extensions import TypedDict

import apysc as ap


class RectOptions(TypedDict):
    rectangle: ap.Rectangle


def on_timer(e: ap.TimerEvent, options: RectOptions) -> None:
    """
    The handler that the timer calls.

    Parameters
    ----------
    e : ap.TimerEvent
        Event instance.
    options : RectOptions
        Optional arguments dictionary.
    """
    rectangle: ap.Rectangle = options["rectangle"]
    rectangle.visible = rectangle.visible.not_


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_rect(x=50, y=50, width=50, height=50)

options: RectOptions = {"rectangle": rectangle}
ap.Timer(on_timer, delay=1000, options=options).start()

ap.save_overall_html(dest_dir_path="do_and_graphics_base_prop_abstract_visible/")

For more details, please see the following:

rotation interfaces

The rotation_around_center property, get_rotation_around_point method, and set_rotation_around_point method can get/set the rotation angle.

Display the code block:
from typing_extensions import TypedDict

import apysc as ap


class RectOptions(TypedDict):
    rectangle: ap.Rectangle


def on_timer(e: ap.TimerEvent, options: RectOptions) -> None:
    """
    The handler that the timer calls.

    Parameters
    ----------
    e : ap.TimerEvent
        Event instance.
    options : RectOptions
        Optional arguments dictionary.
    """
    rectangle: ap.Rectangle = options["rectangle"]
    rectangle.rotation_around_center += 1


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_rect(x=50, y=50, width=50, height=50)

options: RectOptions = {"rectangle": rectangle}
ap.Timer(on_timer, delay=ap.FPS.FPS_60, options=options).start()

ap.save_overall_html(dest_dir_path="do_and_graphics_base_prop_abstract_rotation/")

For more details, please see the following:

scale interfaces

The scale_x_from_center property, scale_y_from_center property, get_scale_x_from_point method, set_scale_x_from_point method, get_scale_y_from_point method, and set_scale_y_from_point method can get/set the scale values.

Display the code block:
from typing_extensions import TypedDict

import apysc as ap


class RectOptions(TypedDict):
    rectangle: ap.Rectangle
    scale_value: ap.Number


def on_timer(e: ap.TimerEvent, options: RectOptions) -> None:
    """
    The handler that the timer calls.

    Parameters
    ----------
    e : ap.TimerEvent
        Event instance.
    options : RectOptions
        Optional arguments dictionary.
    """
    rectangle: ap.Rectangle = options["rectangle"]
    scale_value: ap.Number = options["scale_value"]
    rectangle.scale_x_from_center += scale_value
    rectangle.scale_y_from_center += scale_value

    with ap.If(rectangle.scale_x_from_center >= 2.0):
        scale_value.value = -0.01
        ap.Return()

    with ap.If(rectangle.scale_y_from_center <= 0.5):
        scale_value.value = 0.01
        ap.Return()


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_rect(x=50, y=50, width=50, height=50)

scale_value: ap.Number = ap.Number(0.01)
options: RectOptions = {"rectangle": rectangle, "scale_value": scale_value}
ap.Timer(on_timer, delay=ap.FPS.FPS_60, options=options).start()

ap.save_overall_html(dest_dir_path="do_and_graphics_base_prop_abstract_scale/")

For more details, please see the following:

flip properties

The flip_x and flip_y properties can get/set the flip (reflection) setting.

Display the code block:
from typing_extensions import TypedDict

import apysc as ap


class LineOptions(TypedDict):
    line: ap.Line


def on_timer(e: ap.TimerEvent, options: LineOptions) -> None:
    """
    The handler that the timer calls.

    Parameters
    ----------
    e : ap.TimerEvent
        Event instance.
    options : LineOptions
        Optional arguments dictionary.
    """
    line: ap.Line = options["line"]
    line.flip_x = line.flip_x.not_


ap.Stage(
    background_color=ap.Color("#333"),
    stage_width=150,
    stage_height=150,
    stage_elem_id="stage",
)
sprite: ap.Sprite = ap.Sprite()
sprite.graphics.line_style(color=ap.Color("#fff"), thickness=5)
line: ap.Line = sprite.graphics.draw_line(x_start=50, y_start=50, x_end=100, y_end=100)

options: LineOptions = {"line": line}
ap.Timer(on_timer, delay=1000, options=options).start()

ap.save_overall_html(dest_dir_path="do_and_graphics_base_prop_abstract_flip/")

For more details, please see the following:

skew properties

The skew_x and skew_y properties can get/set the skew-value.

Display the code block:
from typing_extensions import TypedDict

import apysc as ap


class RectOptions(TypedDict):
    rectangle: ap.Rectangle


def on_timer(e: ap.TimerEvent, options: RectOptions) -> None:
    """
    The handler that the timer calls.

    Parameters
    ----------
    e : ap.TimerEvent
        Event instance.
    options : RectOptions
        Optional arguments dictionary.
    """
    rectangle: ap.Rectangle = options["rectangle"]
    rectangle.skew_x += 1


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_rect(x=50, y=50, width=50, height=50)

options: RectOptions = {"rectangle": rectangle}
ap.Timer(on_timer, delay=ap.FPS.FPS_60, options=options).start()

ap.save_overall_html(dest_dir_path="do_and_graphics_base_prop_abstract_skew/")

For more details, please see the following:

See also