Q:

Fibonacci Boxes

I know there's a lot of Fibonacci questions and answers on Stack overflow and the web in general, but this is a problem that's been vexing me for a while now, and i can't seem to crack it or find a solution. 
Creating Fibonacci algorithms are easy enough, there's plenty of them, but i'm trying to create the boxes in a spiral formation graphically using C#. This is not for Uni or anything, it's just a problem that i've spent way too much time on that i now need to find a solution for, if you know what i mean? 
Here's what i've got so far, now i did have a better configuration, but with countless hours of revising the code, this is what i have at the moment:
public partial class Form1 : Form
{
    public const int FIBNUM = 6;
    public const int CENTRE = 10;
    public const int SIZE = 10;
    public const int OFFSET = 100;

    public Form1()
    {
        InitializeComponent();

        drawSpiral();
    }

    private int fib(int n)
    {
        switch (n)
        {
            case 0:
                return 0;
            case 1:
                return 1;
            default:
                return fib(n - 1) + fib(n - 2);
        }
    }

    private void drawSpiral()
    {
        if (pictureBox1.Image == null)
        {
            pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
        }

        using (Graphics g = Graphics.FromImage(pictureBox1.Image))
        {
            Rectangle r = new Rectangle(0, 0, 0, 0);

            int fibnum = 0;
            int centre = 0;
            int size = 0;
            int cnt = 0;

            for (int n = 1; n <= FIBNUM; n++)
            {
                fibnum = fib(n);
                centre = fibnum * CENTRE;
                size = fibnum * SIZE;

                ++cnt;
                if (cnt == 1)
                {
                    if (n == 1)
                    {
                        r = new Rectangle(fibnum + OFFSET, fibnum + OFFSET, size, size);
                        g.DrawRectangle(Pens.Red, r);

                        r = new Rectangle((fibnum + size) + OFFSET, fibnum + OFFSET, size, size);
                        g.DrawRectangle(Pens.Purple, r);

                        n++;
                    }
                    else
                    {
                        r = new Rectangle((centre - size) + OFFSET, (centre - size) + OFFSET, size, size);        
                        g.DrawRectangle(Pens.Black, r);
                    }
                    continue;
                }
                if(cnt == 2)
                {
                    r = new Rectangle((fibnum) + OFFSET, (fibnum - size) + OFFSET, size, size);
                    g.DrawRectangle(Pens.Blue, r);
                    continue;
                }
                if (cnt == 3)
                {
                    r = new Rectangle((fibnum - size) + OFFSET, (fibnum - size) + OFFSET, size, size);
                    g.DrawRectangle(Pens.Green, r);

                    continue;
                }
                if (cnt == 4)
                {
                    r = new Rectangle((fibnum - size / 2) + OFFSET, (fibnum - size) + OFFSET, size, size);
                    g.DrawRectangle(Pens.Gray, r);
                }
                cnt = 0;       
            }
        }
        pictureBox1.Invalidate();
    }

I've taken an image from wikipedia of what it is i'm trying to create graphically :

Thanks in advance.

A:

I think your code is too complicated, because you try to do a lot at once. Consider the following code where the spiral is drawn around the origin, without scaling and translating:
// the current fibonacci numbers
int current = 1;
int previous = 0;

// the current bounding box
int left = 0;
int right = 1;
int top = 0;
int bottom = 0;

// the number of boxes you want to draw
const int N = 10;

for (int i = 0; i < N; i++) {
    switch (i % 4) {
        case 0: // attach to bottom of current rectangle
            drawRectangle(g, left, right, bottom, bottom + current);
            bottom += current;
            break;
        case 1: // attach to right of current rectangle
            drawRectangle(g, right, right + current, top, bottom);
            right += current;
            break;                
        case 2: // attach to top of current rectangle
            drawRectangle(g, left, right, top - current, top);
            top -= current;
            break; 
        case 3: // attach to left of current rectangle
            drawRectangle(g, left - current, left, top, bottom);
            left -= current;
            break; 
    }

    // update fibonacci number
    int temp = current;
    current += previous;
    previous = temp;
}

You can then deal with the actual drawing part in the separate method drawRectangle (I left out all details about the actual graphics objects, but you can probably do that yourself).
const int SCALE = 5;
const int OFFSET = 150;

private void drawRectangle(Graphics g, int left, int right, int top, int bottom)
{
    g.DrawRectangle(Pens.Red, new Rectangle(SCALE * left + OFFSET, 
                                            SCALE * top + OFFSET, 
                                            SCALE * (right - left),
                                            SCALE * (bottom - top)));
}

Output:

