Draw a curve with negative tension in C#

[negative tension]

The post Draw a curve with varying tensions in C# uses the Graphics class’s DrawCurve method to draw a set of curves with different tensions.

While experimenting with that example, I tried drawing a curve with a negative tension, fully expecting the DrawCurve method to throw an exception. To my surprise, the method drew a curve and even produced the interesting result shown above. This example is similar to the previous one except it draws a single curve with tension -2.

The following code shows where the program draws its curve with negative tension.

//for (int t = 0; t <= 20; t += 2)
for (int t = 20; t <= 20; t += 2)
{
    pen.Color = Color.FromArgb(255 * t / 20, 0, 255 - 255 * t / 20);
    e.Graphics.DrawCurve(pen, Points.ToArray(), -t / 10f);
}

[negative tension]

The for loop loops over the single value 20, so it draws only one curve. Replace it with the commented out version to produce a set of curves with negative tension much like the previous example does. The picture on the right shows the result.


Download Example   Follow me on Twitter   RSS feed   Donate




About RodStephens

Rod Stephens is a software consultant and author who has written more than 30 books and 250 magazine articles covering C#, Visual Basic, Visual Basic for Applications, Delphi, and Java.

This entry was posted in drawing, graphics and tagged , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *