Looking at Chaos
Written by Mike James   
Saturday, 05 September 2009
Article Index
Looking at Chaos
Scrolling to plot progress


The only problem with this sort of display is that it doesn’t really show you what the iteration is doing as the bifurcation proceeds. To do this we need to add another picturebox to plot the progress of the iteration for each value of a. Make the picturebox that you add as wide as you can.

To make the plot look like a strip chart or oscilloscope display a Scroll extension method is added to the PictureBox class. See Stripchart Scrolling to find out how this all works. Add the following static class to the program:

public static class MyExtensions
public class RECT
public Int32 left;
public Int32 top;
public Int32 right;
public Int32 bottom;
private static extern int
System.IntPtr hWnd,
int dx,
int dy,
RECT prcScroll,
RECT prcClip,
System.IntPtr hrgnUpdate,
RECT prcUpdate,
System.UInt32 flags
public static void Scroll(
this PictureBox BP, int dx, int dy)
dx, dy, null, null,
IntPtr.Zero, null, 2);


using System.Runtime.InteropServices;

The complete new version of the Click event handler is:

 private void button1_Click(
object sender, EventArgs e)
Bitmap  BImage1 = new Bitmap(
pictureBox1.BackgroundImage = BImage1;

Double a;
Graphics G =
for (int y = 0; y < BImage1.Height; y++)
a = 2.95 + (4 - 2.95) *
y / BImage1.Height;
Double x = 0.2;
for(int i = 1;i<500;i++)
x = a * x * (1 - x);

for ( int i= 1; i < 500; i++)
x = a * x * (1 - x);
x * BImage1.Width), y,Color.Green);
int y1 =(int) (x * pictureBox2.Height);
G.DrawLine(Pens.Red, 0, y1, 0, y1 + 1);
pictureBox2.Scroll(1, 0);

This simply plots the data as the bifurcation diagram is plotted. On most machines this works so quickly that it looks like a display on an oscilloscope.


Bifurcation diagram with stripchart plot

When you run the program notice the way that the population graph changes as additional stable points enter the bifurcation diagram. Also notice the way that the “signal” changes from periodic to what looks like random as the bifurcation diagram changes to chaos. You will need to watch the entire performance more than once because there is a lot to look at and take in. If you want to zoom in on a vertical section of the bifurcation diagram then change the 2.9 and 4 in the first instruction in the for loop.

If you would like the code for this project then register and click on CodeBin.





Last Updated ( Saturday, 05 September 2009 )

RSS feed of all content
I Programmer - full contents
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.