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.

    X(n) = Sin(A * Y(n - 1)) - Z(n - 1) * Cos(B * X(n - 1))
Y(n) = Z(n) * Sin(C * X(n - 1)) - Cos(D * Y(n - 1))
Z(n) = Sin(X(n - 1))

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;

// Plot the point.
switch (SelectedPlane)
{
case Plane.XY:
bm.SetPixel((int)(x * xscale + xoff), (int)(y * yscale + yoff), FgColor);
break;
case Plane.YZ:
bm.SetPixel((int)(y * yscale + yoff), (int)(z * zscale + zoff), FgColor);
break;
case Plane.XZ:
bm.SetPixel((int)(x * xscale + xoff), (int)(z * zscale + zoff), FgColor);
break;
}
}

// Refresh.
picCanvas.Refresh();

// 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.

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.