BLOG.CSHARPHELPER.COM: Draw a fractal Pickover strange attractor in C#
Draw a fractal Pickover strange attractor in C#
Suppose you perform a series of iterations of equations to generate points. Sometimes the points converge to one or more points. For example, the equations X(n) = X(n - 1) / 2, Y(n) = Y(n - 1) / 3 approach the point (0, 0) as n grows large.
The points to which the equations converge is called an attractor.
Some equations are drawn towards a collection of points that is not easily defined but that somehow has a coherent shape. These points are called a strange attractor.
Clifford Pickover discovered that the following equations generate points that are drawn to a strange attractor.
Here A, B, C, and D are constants.
The following code plots these points.
// Draw the curve. private void DrawCurve() { // Get the parameters and otherwise get ready. Prepare();
// Start drawing. double x = X0, y = Y0, z = Z0; while (Running) { // Plot a bunch of points. for (int i = 1; i<=1000; i++) { // Move to the next point. double x2 = Math.Sin(A * y) - z * Math.Cos(B * x); double y2 = z * Math.Sin(C * x) - Math.Cos(D * y); z = Math.Sin(x); x = x2; y = y2;
// Check events to see if the user clicked Stop. Application.DoEvents(); } }
Use the program's controls to plot X-Y, X-Z, or Y-Z projections of the points in different colors. You can also change the equations' constants and starting value to see what happens.
Comments