CONTENTS

Home
Updates
Software
Electronics
Android / iOS
Videos
Music
Resume
Contact



HTTPS VERSION


Mandelbrot Animations

Posted: January 9, 2005

Introduction

The purpose of this project is to demonstrate distributed computing for generating animations of zooming into Mandelbrot pictures. In other words, to use multiple computers all networked together to work on a complicated math formula to generate mandelbrot animations.

Mandelbrots are pictures that are generated from the math equation z = z^2 + c where c is a complex number (x + yi) and x and y are coordinates. A set of coordinates are put into the formula and computed for a number of iterations. If at any time z becomes more than 4, the coordinates are not considered in the mandelbrot set and a color is put on the screen. The color depends on how many iterations went by before the coordinates failed. If z never becomes more than 4, a black dot is put on the screen. Here are a couple example pictures:

Related Projects @mikekohn.net

Mandelbrots: mandel server, python Mandelbrot, Mandelbrots SIMD, j2me Mandelbrot

Pictures

Coordinates: (-2.00,-1.00) to (1.00,1.00)
Coordinates: (-0.785799,-0.146523) to (-0.685693,-0.079802)



I posted an example video along with some improvised guitar stuff I did a while ago. It doesn't fit the video so well, but it sounds better than dead silence. The song is called "green.mp3" and the full mp3 can be downloaded from the music section of my website. https://youtu.be/6jgPYaCJLFc

Anyway, I was curious about distributed computing, so I wrote this client/server Mandelbrot generator. The server is a modified version of my Naken Chat chat server. To use this program, simply run the mandel_server program. It will create a file called frames.dat in the frames directory. This file keeps track of all the frames that have been made, this way if the server dies when you start it over it will keep going where it left off. If you want mandel_server to create a new sequence of images, you must delete this file.

Before running the mandel_server you can configure it using the mandel_server.conf file. In this file you set the width/height of the output GIF image, the real/imaginary starting coordinates, the real/imaginary ending coordinates, the number of iterations, and the number of frames to create.

After starting the server, you need a client to do all the dirty work. In the mandel_client directory, type: ./mandel_client <ip of server> (or if you're on Windows, open up a DOS prompt or a run box, and type: mandel_client <ip of server>). You need to replace the part with the actual IP address or hostname of the computer that is running the server. So if your mandel_server is running on 192.168.1.50, you'd type: mandel_client 192.168.1.50. After the client starts, it will connect to the server. The server will give it coordinates to calculate and the client will calculated it and return a GIF image back to the server. The server will organize all the images in the frames directory so you can create an mpeg out of it. The client will keep requesting images to work on until you press ctrl-c to remove yourself from the "cluster" or the mandel_server is done and the images are all ready.

Keep in mind that different processor architectures handle floating point numbers differently. In other words, if one of your clients is an Apple Mac, another an Intel PC, another a SGI MIPS, etc, you may get inconsistent results. Altho, my last animation I created was done with a Mac running OSX, an AMD Athlon XP running Linux, and an AMD K6-2 running Linux, and I saw no strangeness there :).

Well, problems with this program so far include:
1) It's not very user friendly. It's more of a proof of concept.
2) It's not secure. Maybe I should add a "hosts allow" file like Naken Chat has
3) It's probably buggy. I wrote it pretty quick. It does create really neat images tho.

In the future I might also add a feature so it can do more than 16 colors, and the mandel_server will tell all the clients which colors to use.

You can download and test it here:
mandel-2005-01-09.tar.gz (Unix Source)
mandel-2005-01-09.zip (Windows Binaries)

gif2avi

After you create a set of Mandelbrot pictures, if you'd like to string the images together into an avi animation, I wrote a seperate gif2avi program to do this. This program was put together pretty quickly, so maybe there are bugs. It can do both fully raw avi or rle8 compressed avi. I created a 1000 frame mandelbrot animation and used gif2avi to make a raw avi and then the same frames as rle8 encoded. The raw avi was 307megs in size while the rle8 file was 24megs. Therefore, I hardcoded the program to always use rle8. If you'd like me to change that let me know, but other than that I think rle8 is the way to go (hopefully I implemented it correctly :). Anyway, to use this program you would type:

gif2avi out.avi /opt/mandel/mandel_server/frames/ 30

This assumes your output avi file will be called out.avi, the directory that holds all your gif images (which the images must be named with the format frameXXXXX.gif where XXXXXX is a number like 00000 indicating the frame number). The 30 means you want the video to play at 30 frames per second. This will create a lossless avi video which can be then transcoded to an mpeg or such.

This program compresses really nicely and works really well with this mandelbrot program. I'm not sure how well it would work with other image files. It assumes you don't have a lot of colors in your image and each gif has the same palette (or at least similar). I think it also may have problems if the width of your image is not 4 bytes aligned, but I don't feel like testing it. Anyway, if you'd like to download it, here it is:

gif2avi-2012-02-09.tar.gz (Unix Source)
gif2avi-2012-02-09.zip (Windows Binaries)

NOTE:As of February 9, 2012, I was asked to add BMP support, so gif2avi will look for frame*.bmp files now also. Also, I updated a bit of the code and found a bug that the outputted video was upside-down. I fixed this.

Copyright 1997-2018 - Michael Kohn