# Monthly Archives: May 2017

## 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

## Make silly eyes that track the mouse without flicker in C#

The example Make silly eyes that track the mouse in C# shows how to make eyes track the mouse position, but if you look closely as that program runs you will see a noticeable flicker. The solution is quite simple: … Continue reading

Posted in games, geometry, graphics | | 1 Comment

## Make silly eyes that track the mouse in C#

This example uses a Timer named tmrTick to track the mouse. Its Tick event handler, which is shown in the following code, updates the eyes. // The previous mouse location. private Point OldMousePos = new Point(-1, -1); // See if … Continue reading

Posted in games, geometry, graphics | | 2 Comments

## Compare the performance of simple arithmetic operations in C#

I saw a post the other day that said division was the slowest arithmetic operation so I wrote this example to see exactly how the performance of multiplication, division, addition, and subtraction differ with floating point numbers. When you click … Continue reading

Posted in mathematics, performance | | 1 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 | | 3 Comments

## Graph event probabilities in C#

The example Calculate the probability of an event occurring in a given number of trials in C# shows how to calculate event probabilities. This example graphs the results. You can use the example to get some feel for how the … Continue reading

## Find the number of trials for an event probability in C#

The post Understand probabilities of unrelated events (and escaping zombies) explains how to calculate the number of trials necessary to reach a certain probability of an event occurring. It explains that if an event has a probability P of occurring … Continue reading

## Calculate the probability of an event occurring in a given number of trials in C#

The post Understand probabilities of unrelated events (and escaping zombies) explains how to calculate the probability of an event occurring in a certain number of trials. It explains that if an event has a probability P of occurring at each … Continue reading

Posted in mathematics | | 1 Comment

## Understand probabilities of unrelated events (and escaping zombies)

Given some event with a relatively low probability, what is the probability that the event will occur if you perform many trials? For example, suppose the zombie apocalypse has arrived and there’s a 1% chance that the zombies will get … Continue reading

Posted in mathematics | | 2 Comments

## Display reusable dialog forms in C#

The example Make a dialog with standard dialog features in C# shows the most common approach to making dialogs. Whenever it needs to display the dialog, the main program initializes a new instance of it and displays it. If the … Continue reading