Search code examples
c#drawingspiral

C# Draw Spiral Fill


I have a question on Spiral Drawing.

The source below Referred from the link.
http://www.java2s.com/Code/CSharp/2D-Graphics/Spiral.htm

Spiral gives you space.

I want the Spiral to fill the screen.

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);
}

Image
https://i.sstatic.net/Ijrjp.png


Solution

  • For sheer morbid curiosity, i created a new winforms application and pasted your code

    This was my results

    enter image description here

    If this is not your desired results, please update your question to be more specific, include the picture, the desired results, and why its not working