GraphicsBase skew_x and skew_y interfaces¶
This page explains the GraphicsBase
class (base class of each graphic, such as the Rectangle
) skew_x
and skew_y
property interfaces.
What interfaces are these?¶
The skew_x
property skews an object’s x-axis. Conversely, the skew_y
property skew a y-axis. These interfaces have getter and setter interfaces.
Each interface value type is the Int
value.
The following example shows you the default rectangle (left) and the skewed 50px in the x-direction rectangle (right).
import apysc as ap
ap.Stage(
stage_width=250,
stage_height=150,
background_color=ap.Color("#333"),
stage_elem_id="stage",
)
sprite: ap.Sprite = ap.Sprite()
sprite.graphics.begin_fill(color=ap.Color("#0af"))
left_rectangle: ap.Rectangle = sprite.graphics.draw_rect(
x=50, y=50, width=50, height=50
)
right_rectangle: ap.Rectangle = sprite.graphics.draw_rect(
x=150, y=50, width=50, height=50
)
right_rectangle.skew_x = ap.Int(50)
ap.save_overall_html(dest_dir_path="graphics_base_skew_x_basic_usage/")
The following example skews the rectangle in the y-direction incrementally.
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 : TimerEvent
Event instance.
options : dict
Optional arguments dictionary.
"""
rectangle: ap.Rectangle = options["rectangle"]
rectangle.skew_y += 1
ap.Stage(
stage_width=150,
stage_height=150,
background_color=ap.Color("#333"),
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}
timer: ap.Timer = ap.Timer(handler=on_timer, delay=ap.FPS.FPS_60, options=options)
timer.start()
ap.save_overall_html(dest_dir_path="graphics_base_skew_y_incremental_basic_usage/")
skew_x property API¶
Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.
[Interface summary]
Get a current skew x value of the instance.
[Returns]
skew_x
: IntCurrent skew x value of this instance.
[Examples]
>>> import apysc as ap
>>> stage: ap.Stage = ap.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
... )
>>> rectangle.skew_x = ap.Int(50)
>>> rectangle.skew_x
Int(50)
skew_y property API¶
Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.
[Interface summary]
Get a current skew y value of the instance.
[Returns]
skew_y
: IntCurrent skew y value of the instance.
[Examples]
>>> import apysc as ap
>>> stage: ap.Stage = ap.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
... )
>>> rectangle.skew_y = ap.Int(50)
>>> rectangle.skew_y
Int(50)