Saturday, July 2, 2011

Old but still great code

I decided to resurrect some old 3D dot rotation code (1993). It was in C so I converted it to C# (not a big stretch) and it works pretty good. The key was double buffering.

Right now I am working on a whole 'font' that will allow me to rotate just about any string.

(these are predefined elsewhere but thought I would include them so you could see how the are created)
offScreenBmp = new Bitmap(this.Width, this.Height);
offScreenDC = Graphics.FromImage(offScreenBmp);
backBrush = new SolidBrush(Color.Lime); // i set the form transparency key to this
this.TopMost = true;

the 'display' code looks like this (I will be cleaning it up later):

private void DoDotAnimation()
{
while (! ClosingIt)
{
MoveDots(); // never guess what this does...
Graphics clientDC = this.CreateGraphics();

offScreenDC.FillRectangle(backBrush, 0, 0, this.Width, this.Height);

Color newColor = System.Drawing.Color.Red;

for (i = 0; i < PointsN; i++) // run through the dots array and draw them { if ((TheNewDots[i, 0] > -1) && (TheNewDots[i, 1] > -1))
offScreenDC.DrawEllipse(new Pen(newColor, 2), TheNewDots[i, 0], TheNewDots[i, 1], dotSize, dotSize);
}
clientDC.DrawImage(offScreenBmp, 0, 0);

Application.DoEvents();
}
}

No comments:

Post a Comment

Comments are moderated. We're only going to allow stuff that we find funny, interesting, or just plain for the heck of it. If you don't like that, feel free to leave.

Copyright Realm Laboratories, LLC