Friday 27 February 2009

Flame fractal generator


If you have an interest in computer science or mathematics you have probably already heard of fractals. Well, flame fractals are strictly speaking not fractals. They are generated through an algorithm called Iterated Function Systems, which simply consists in iteratively transforming a point in the plane a certain number of times and tracing the historigram of where that point landed (using one of n predefined transformations in the plane at random for each step). There are a few pictures at the bottom of this article.
The main particularity of flame fractals is that they use non-linear functions for the iteration, which results in much more varied forms. The colouring is a little bit more subtle, if you want an idea of how it is done, I would advise you to read this excellent paper written by Scott Draves.

The program is technically interesting to write, since smooth, aesthetically pleasing pictures are usually difficult to compute without using either lots of computing time or memory space. This is mainly because of rendering techniques such as super-sampling (rendering the picture in high resolutions and scaling it down to obtain smoother pictures, very effective but very costly) and High Dynamic Range processing. Also, many millions or even up to a billion iterations are necessary to avoid getting a pixelated picture.

The program here isn't exactly the most user-friendly, but has a small GUI to play with a few parameters, and a binary historigram showing a preview of the final image. Usually to render my flame fractals, I modify the arguments directly in the code which is much quicker. A few shortcomings of this GUI are that you can only specify 2 transformations, you can not specify which color to associate with each transformation and a few other parameters such as output image resolution (set to 1000x1000 for memory space reasons) and number of iterations (10 million for the output image, 10 000 for the preview image). Here's a list of the different transformations I have implemented :
1. Linear (if you want to create "conventional" fractals like Sierpinski's gasket)
2. Spherical (Usually helps the system being contractive, i.e. helps to keep the point inside the screen)
3. Horseshoe
4. Ex
5. Fisheye (usually get good pictures with this one)
6. Heart

Since the program can still be improved in many ways and is my favourite personal project so far, it is far from being abandoned. Also a very recommended project for programmers.

Written in : February 2008
Link for the application : Here (Important note : Before using this program create a C:\Java\pic\ folder or else the fractal won't render)
Skills used : GUI making, Input/Output handling, Memory/Complexity optimization.

Note : All my programs are applications, not applets. Post a comment or contact me if you're interested in a source code.

Examples :

Sunday 22 February 2009

Pathfinding with the A* algorithm


My first step into Artificial Intelligence. The A* algorithm finds the shortest path from a point to another using a heuristic (you could say a "guess"), which estimates the distance from a node to the goal using a particular path in order to prioritize the nodes that are most likely to be on the shortest path, therefore reducing memory cost and complexity. The heuristic used here is a diagonal heuristic, which simply estimates the distance to the goal by the number of nodes separating it from the goal in a straight line through walls, also allowing diagonal moving. This heuristic is a very common one because it is simple to program and works well enough if you don't have so many nodes.

The blue tile shows the starting point, the red tiles are the path, the grey tiles are the area which has been searched and the black ones are the tiles through which we don't allow the path to go through also called "walls".

Just start by placing your starting point, then add the walls and press start when you want to place the goal. Enjoy the beautiful optimal path you get, push Clear and start all over again.

Interesting project, I would recommend it to any practicing Java programmer.

Written in : March 2007
Link for the application : Here
Skills used : GUI making, Structure handling, A* algorithm implementation.

Note : All my programs are applications, not applets. Post a comment or contact me if you're interested in a source code.

Saturday 21 February 2009

Image to HTML Converter


This tool has absolutely no other purpose than training Java programming skills, although it can be fun to play with. It converts pictures to HTML files, which means that the produced HTML files contain text colored like the pixels of the input image. See example below.

If you intend to use this tool, do not convert large pictures with it, 400x400 gives already huge output HTML files which you won't be able to view in one screen anyway. 40x40 is a recommended size.

Written in : March 2007
Link for the application : Here
Skills used : GUI making, Input/Output handling.

Note : All my programs are applications, not applets. Post a comment or contact me if you're interested in a source code.

Example :
Source image :
Output file : Here

Game of Life

Based on the British mathematician Conway's Game of Life, this application simulates cell reproduction in a very simple way. The user starts by putting cells in the tiles of his choice on the grid and launches it. During each step, cells are born or die, depending on how many cells are around them. If there are too many or not enough, the cell will die, if there are just enough, a cell will be born. This very simple procedure gives a surprisingly good simulation of cell growth and can lead to interesting studies of stable patterns, which after a certain amount of steps come back to their original position.

Written in : January 2007
Link for the application : Here
Skills used : GUI making.

Note : All my programs are applications, not applets. Post a comment or contact me if you're interested in a source code.

Determinant Computation


This was one of the first programs with a Guide User Interface (GUI) that I wrote. My goal was to compute a determinant using the recursive Laplace's formula (which probably gives a horrible computational complexity) in order to get used to Java.

Written in : December 2006
Link for the application : Here
Skills used : Recursive functions, GUI making.

Note : All my programs are applications, not applets. Post a comment or contact me if you're interested in a source code.