Programming in Ump

Mandelbrot set drawer
	Function mandelbrot
	{
		Variable itermax, pic, c, x, y, z, iter;  // defines all variables that will be used

		itermax = 25.0;
		pic = picture( 100, 100 );
	
		x = 0.0;
		while( x < 100.0 )
		{
			y = 0.0;
			while( y < 100.0 )
			{
				z = 0.0;
				c = x * 4.0/100.0 - 2.0 + i( y * 4.0/100.0 - 2.0 );  // setup variables

				iter = 0.0;
				while( iter < itermax  and  |z| < 2.0 )  // run no more than itermax iterations also break when |z| is greater than 2
				{
					z = z*z + c;  // calculate an iteration

					iter++;
				}
				pic.set_pixel( x, y, Red * ( log iter / log itermax ) );

				y++;
			}
			x++;
		}
		show pic;
		return pic;
	}
	
Save this as mandelbrot.ump, and type mandelbrot.

While this work, it's not very useful to have this function draw the same fractal at the same size everytime.
So let's add some arguments to control size and color.
	Function mandelbrot( width, height, color )
	{
		Variable itermax, pic, c, x, y, z, iter;  // defines all variables that will be used

		itermax = 25.0;
		pic = picture( width, height );
	
		x = 0.0;
		while( x < width )
		{
			y = 0.0;
			while( y < height )
			{
				z = 0.0;
				c = x * 4.0/width - 2.0 + i( y * 4.0/height - 2.0 );  // setup variables

				iter = 0.0;
				while( iter < itermax  and  |z| < 2.0 )
				{
					z = z*z + c;  // calculate an iteration

					iter++;
				}
				pic.set_pixel( x, y, color * ( log iter / log itermax ) );

				y++;
			}
			x++;
		}
		show pic;
		return pic;
	}
	
Save as mandelbrot.ump, and type delete "mandelbrot" then mandelbrot(150,100,Blue).
(we must remove the old version of mandelbrot else Ump won't load the function from the file)

This way different sized/colored mandelbrots is possible to be drawn.
But what happens if mandelbrot( 50, 50, 5 ) is typed.
Then color will be 5, and 5 isn't a valid color matrix.
To eliminate these kinds of errors, create the function like this...
	Function mandelbrot( Integer width, Integer height, Matrix color )
	{
		...
	}
	
width and height must then be integers and color must be a matrix when mandelbrot is called.
Inside of mandelbrot these variables can change type just as easy as any other variable.

The different kinds of arguments is
Integer
Real
Complex
Matrix
String
Picture
Array
Boolean