查詢

UI\Draw\Path::arcTo()函式—用法及示例

「 在繪圖路徑中新增一段弧線,該弧線透過指定的控制點和半徑來定義 」


函式名稱: UI\Draw\Path::arcTo()

適用版本: PHP 7.4 及以上版本

函式說明: UI\Draw\Path::arcTo() 方法用於在繪圖路徑中新增一段弧線,該弧線透過指定的控制點和半徑來定義。

用法:

public UI\Draw\Path::arcTo(
    float $x, 
    float $y, 
    float $radiusX, 
    float $radiusY, 
    float $rotation, 
    bool $largeArcFlag, 
    bool $sweepFlag
): void

引數說明:

  • $x (float): 弧線的終點的 x 座標。
  • $y (float): 弧線的終點的 y 座標。
  • $radiusX (float): 弧線的橢圓的 x 軸半徑。
  • $radiusY (float): 弧線的橢圓的 y 軸半徑。
  • $rotation (float): 弧線的橢圓相對於 x 軸的旋轉角度。
  • $largeArcFlag (bool): 指定是否使用大弧線標誌。如果為 true,則使用大弧線;如果為 false,則使用小弧線。
  • $sweepFlag (bool): 指定是否使用順時針弧線標誌。如果為 true,則繪製順時針弧線;如果為 false,則繪製逆時針弧線。

示例:

use UI\Draw\Path;
use UI\Draw\Pen;
use UI\Draw\Brush;
use UI\UI;

$ui = new UI();
$window = new UI\Window("Window", 800, 600, true);

$path = new Path();
$path->addRectangle(100, 100, 200, 200);

// 在路徑中新增一段弧線
$path->arcTo(400, 400, 100, 100, 0, true, true);

$pen = new Pen(0xFF0000FF, 2);
$brush = new Brush(0xFF00FF00);

$window->onDraw(function ($event) use ($path, $pen, $brush) {
    $area = $event->getArea();
    $context = $event->getContext();

    $context->setStroke($pen);
    $context->setFill($brush);

    // 繪製路徑
    $context->strokePath($path);
    $context->fillPath($path);
});

$window->show();
$ui->main();

上述示例程式碼建立了一個視窗,視窗中繪製了一個矩形和一個由 arcTo() 方法定義的弧線。弧線的起點是矩形的右下角,終點是座標 (400, 400)。弧線的橢圓半徑為 100x100,旋轉角度為 0,使用大弧線標誌和順時針弧線標誌。視窗中繪製的路徑透過 strokePath()fillPath() 方法進行描邊和填充操作。

補充糾錯
熱門PHP函式
分享連結