Wednesday, June 2, 2010

Chaotic Maps!

This is the first release of "fastmapmap", a program I wrote that plots 2D chaotic maps. A discrete chaotic map will take the point (x,y) to a new (x_, y_) based on a function. For example, the Henon map takes the point (x,y) to (y+1-a*x*x, b*x), where a and b are constants. One can draw a "portrait" of a map by choosing an (x0, y0) and repeatedly evaluating the function, shading in each point that is landed on. Depending on the values of a and b, sometimes the point moves off to become very large, or sometimes the point alternates jumping between two or more values. Other times, the points shade in a region in a complicated way, never repeating, which is a chaotic orbit.

The program fastmapmap can draw these portraits in real time. (I put some effort into optimization). The parameters a and b can be quickly changed with the arrow keys. The plot can be easily navigated; hold alt and drag the mouse to zoom in on a region.

The program is called fastmapmap because an additional plot can be drawn that is a "map" of the behavior of the map. The x axis represents the constant a and the y axis is b. In this plot, black areas are periodic, red areas escape to infinity, and colored areas are chaotic. So, the plot can depict which parameter values may be interesting to observe.
It's cross-platform, tested in Windows and Ubuntu. Try it! Download Windows | Source (GPL)

A short tutorial:
  • Open fastmap.exe
  • Tap the right arrow a bit to change the value of a.
  • Press Ctrl-s, type 'test', and press Enter to save as test.cfg
  • Ctrl-click on the shape to zoom in, Shift-click to zoom out
  • Press Ctrl-o, type 'test' and press Enter to open our test.cfg
  • Press Alt-b and watch the shapes move
  • Press Alt-b again to stop movement
  • Click the cross-hairs icon to show the diagram. Click in the diagram.
  • Click the "..." icon to read what else can be done.
The program can easily create animations. Hit Alt-B and watch the shapes start to move. Use Ctrl-F1 through Ctrl-F9 to set a keyframe. Refer to readme.txt for all of the other features.

 

 

 

I came up with other drawing modes. In the following, x and y represent x0 and y0, and the color is chosen according to the value after 20 iterations.




Assigning colors based on quadrant:





I invented this drawing method originally as way of depicting the action of the Henon map.

 


 

Remember to download: Windows | Source

SDL Text and Dialogs

For one of my recent projects, I wanted dialogs in an sdl program. This small library draws simple "dialogs" to ask the user for text or a number.



Usage:
// where SDL_Surface* pSurface is the screen surface.
char * s; 
s= Dialog_GetText("Enter your name:", "Fred", pSurface);
Dialog_Messagef(pSurface, "Welcome, %s", s);
free(s);

double val = 1.5;
Dialog_GetDouble("Enter a value", pSurface, &val);
int n = 1;
Dialog_GetInt("Choose a number.", pSurface, &n);
if (Dialog_GetBool("Double the number?", pSurface))
  n*=2;
Dialog_Message("Goodbye", pSurface);
freeFonts();


To draw text, I used the code at this page. (I added the ability to have newlines and tabs). It supports lower ascii chars, and code could be improved, but currently suits my purposes. There's also SFont and others.

Source (includes a bitmap font).