※この翻訳ドキュメントはスクリプトによって出力・同期されています。内容が怪しそうな場合はGitHubにissueを追加したり英語の原文の確認をお願いします。
Graphics クラスの draw_circle インターフェイス¶
このページではGraphics
クラスのdraw_circle
メソッドのインターフェイスについて説明します。
インターフェイス概要¶
draw_circle
インターフェイスはベクターグラフィックスの円を描画します。
基本的な使い方¶
draw_circle
インターフェイスはx
とy
、そしてradius
引数を持っています。
x
とy
引数は円の中央座標となります。radius
引数は円の半径となります、幅と高さはradius
引数の2倍の値になります。
import apysc as ap
ap.Stage(
background_color="#333", stage_width=350, stage_height=200, stage_elem_id="stage"
)
sprite: ap.Sprite = ap.Sprite()
# Set the cyan color and draw the circle.
sprite.graphics.begin_fill(color="#0af")
sprite.graphics.draw_circle(x=100, y=100, radius=50)
# Set the dotted-line style and draw the circle.
sprite.graphics.begin_fill(color="")
sprite.graphics.line_style(
color="#fff", thickness=3, dot_setting=ap.LineDotSetting(dot_size=3)
)
sprite.graphics.draw_circle(x=250, y=100, radius=50)
# Draw the inner circle.
sprite.graphics.draw_circle(x=250, y=100, radius=25)
ap.save_overall_html(dest_dir_path="graphics_draw_circle_basic_usage/")
返却値¶
draw_circle
インターフェイスの返却値はCircle
クラスのインスタンスとなります。
このインスタンスはradius
属性や他の基本的な各インターフェイスを持っており生成後に値を更新することができます。
import apysc as ap
ap.Stage(
background_color="#333", stage_width=400, stage_height=400, stage_elem_id="stage"
)
sprite: ap.Sprite = ap.Sprite()
# Draw the small radius circle.
sprite.graphics.begin_fill(color="#0af")
circle: ap.Circle = sprite.graphics.draw_circle(x=200, y=200, radius=25)
# Update circle radius to become the bigger one.
circle.radius = ap.Int(100)
ap.save_overall_html(dest_dir_path="graphics_draw_circle_return_value/")
draw_circle API¶
特記事項: このAPIドキュメントはドキュメントビルド用のスクリプトによって自動で生成・同期されています。そのためもしかしたらこの節の内容は前節までの内容と重複している場合があります。
[インターフェイスの構造] draw_circle(self, *, x: Union[int, apysc._type.int.Int], y: Union[int, apysc._type.int.Int], radius: Union[int, apysc._type.int.Int], variable_name_suffix: str = '') -> '_circle.Circle'
[インターフェイス概要]
円のベクターグラフィックスを描画します。
[引数]
x
: Int or int円の中心のX座標。
y
: Int or int円の中心のY座標。
radius
: Int or int円の半径。
variable_name_suffix
: str, default ‘’JavaScript上の変数のサフィックスの設定です。この設定はJavaScriptのデバッグ時に役立つことがあります。
[返却値]
circle
: Circle生成された円のグラフィックスのインスタンス。
[コードサンプル]
>>> import apysc as ap
>>> stage: ap.Stage = ap.Stage()
>>> sprite: ap.Sprite = ap.Sprite()
>>> sprite.graphics.begin_fill(color="#0af")
>>> circle: ap.Circle = sprite.graphics.draw_circle(x=100, y=100, radius=50)
>>> circle.x
Int(100)
>>> circle.y
Int(100)
>>> circle.radius
Int(50)
>>> circle.fill_color
String('#00aaff')