Tag Archives: algorithms

Animate rainbow colors in C#

The example Map numeric values to and from colors in a color gradient in C# draws a color gradient that uses rainbow colors. This example animates that one. When you click on the color gradient, the following code starts or … Continue reading

Posted in algorithms, animation, graphics, mathematics | Tagged , , , , , , , , , , , , , , , | Leave a comment

Animate exploding 3-dimensional pie slices in C#

The example Draw 3-dimensional pie slices in C# shows how to highlight one or more 3-D pie slices by “exploding” them. This example draws even more attention to the exploded pie slices by animating their explosion. The program controls the … Continue reading

Posted in algorithms, animation, graphics, mathematics, multimedia | Tagged , , , , , , , , , , , , , , , , , , | Leave a comment

Calculate where a line segment and an ellipse intersect in C#

Finding the intersection between a line segment and an ellipse requires a lot of mathematics. It’s not particularly hard mathematics, but if you’d rather skip it, you can use the following links to jump to the other parts of this … Continue reading

Posted in algorithms, drawing, geometry, graphics, mathematics | Tagged , , , , , , , , , , , , , , , , , | 5 Comments

Produce a repeatable series of “random” numbers in C#

The Random class can generate a series of pseudo-random numbers. They’re called “pseudo-random” rather than “random” because the numbers are generated by a mathematical algorithm rather than by some completely unpredictable process such as observing a source of radioactive decay … Continue reading

Posted in algorithms, mathematics | Tagged , , , , , , , , , , , , , | Leave a comment

Generate random polygons in C#

I needed a method for generating random polygons for a graphics program and the following code shows the result. // Make random polygons inside the bounding rectangle. private static Random rand = new Random(); public static PointF[] MakeRandomPolygon( int num_vertices, … Continue reading

Posted in algorithms, geometry, graphics | Tagged , , , , , , , , , | Leave a comment

Calculate the present value of a future amount of money in C#

This example shows how to calculate the present value of a future amount of money. Suppose you want a certain amount of money in a given number of years and you know you can realize a specific interest rate (compounded … Continue reading

Posted in algorithms, mathematics | Tagged , , , , , , , , , , | Leave a comment

Make a 3D globe in WPF and C#

This example shows how you can draw a 3D globe. More generally it shows how you can make a three-dimensional textured sphere in WPF. The example Draw smooth spheres using WPF and C# shows how to make smooth colored spheres. … Continue reading

Posted in algorithms, drawing, geometry, graphics, mathematics, wpf, XAML | Tagged , , , , , , , , , , , , , , , , | Leave a comment

Enumerate TreeView nodes in C#

The previous two posts show two ways you can enumerate TreeView nodes that are checked. The idea is to recursively crawl over the tree’s nodes and pick out the checked ones. Unfortunately that method isn’t easily extendable. For example, if … Continue reading

Posted in algorithms, controls, recursion, user interface | Tagged , , , , , , , , , , , , , , , , | Leave a comment

Yield checked TreeView nodes in C#

The previous example used recursion to traverse the nodes in a TreeView control and fill a list with the nodes that are checked. This example uses a slightly different approach. It traverses the TreeView control’s nodes and uses the yield … Continue reading

Posted in algorithms, controls, recursion, user interface | Tagged , , , , , , , , , , , , , , | Leave a comment

Make a list of checked TreeView nodes in C#

If you set a TreeView control’s CheckBoxes property to true, then the control displays boxes that the user can check to select nodes. In that case you will probably need to find the checked TreeView nodes at some point. Strangely … Continue reading

Posted in algorithms, controls, recursion, user interface | Tagged , , , , , , , , , , , , , | Leave a comment