0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Skia Tips:もつれあう線

Last updated at Posted at 2025-11-08

よれてもつれあう、装飾的な線をSkiaで描画する方法について説明します。

もつれあう線の実装

これはパスエフェクトのちょっと複雑な組み合わせの応用です。
CreateDiscreteでランダムに折れた線を作成し、CreateCornerで角を丸め、CreateSumで複数のよれた線を束ねることで、もつれあう線を表現します。

// もつれあう線のペイント
using var paint = new SKPaint {
    Color = SKColors.Black,
    IsAntialias = true,
    Style = SKPaintStyle.Stroke,
    StrokeWidth = 1.5f,
    // もつれあう線のPathEffect
    PathEffect = SKPathEffect.CreateSum(                // 束ねる
        SKPathEffect.CreateCompose(                     // よれた線3
            SKPathEffect.CreateCorner( 10 ),            // 角を丸める
            SKPathEffect.CreateDiscrete( 10, 5, 2 )     // ランダムに折る
        ),
        SKPathEffect.CreateSum(                         // 束ねる
            SKPathEffect.CreateCompose(                 // よれた線1
                SKPathEffect.CreateCorner( 10 ),        // 角を丸める
                SKPathEffect.CreateDiscrete( 10, 5, 0 ) // ランダムに折る
            ),
            SKPathEffect.CreateCompose(                 // よれた線2
                SKPathEffect.CreateCorner( 10 ),        // 角を丸める
                SKPathEffect.CreateDiscrete( 10, 5, 1 ) // ランダムに折る
            )
        )
    )
};
// 折れ線を描画
using var path = new SKPath();
path.MoveTo( 50, 50 );
path.LineTo( 117, 150 );
path.LineTo( 183, 50 );
path.LineTo( 250, 150 );
canvas.DrawPath( path, paint );

実行すると、以下のように、もつれあう3本の線が描画されます。

tangled_lines.png


総合目次

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?