猿问

C# 绘制螺旋填充

我有一个关于螺旋绘图的问题。


以下来源来自链接。

http://www.java2s.com/Code/CSharp/2D-Graphics/Spiral.htm


螺旋为您提供空间。


我希望螺旋填满屏幕。


protected override void OnPaint(PaintEventArgs pea)

{

  DoPage(pea.Graphics, ForeColor, ClientSize.Width,ClientSize.Height);

}


protected void DoPage(Graphics grfx, Color clr, int cx, int cy)

{

    const int iNumRevs = 3;

    int iNumPoints = iNumRevs * 2 * (cx + cy);

    PointF[] aptf = new PointF[iNumPoints];

    float fAngle, fScale;


    for (int i = 0; i < iNumPoints; i++)

    {

    fAngle = (float)(i * 2 * Math.PI / (iNumPoints / iNumRevs));

    fScale = 1 - (float)i / iNumPoints;


    aptf[i].X = (float)(cx / 2 * (1 + fScale * Math.Cos(fAngle)));

    aptf[i].Y = (float)(cy / 2 * (1 + fScale * Math.Sin(fAngle)));

    }

    grfx.DrawLines(new Pen(clr), aptf);

}

图片

人到中年有点甜
浏览 275回答 1
1回答

30秒到达战场

出于纯粹病态的好奇心,我创建了一个新的 winforms 应用程序并粘贴了您的代码这是我的结果如果这不是您想要的结果,请更新您的问题以使其更具体,包括图片、所需的结果以及为什么它不起作用
随时随地看视频慕课网APP
我要回答