Elements. Build native projects for any modern development platform, using the language(s) of your choice. Oxygene (Object Pascal), C#, Swift, Java, Go. | RemObjects Software

Mandelbrot

Language: Hydrogene, Platform: Cooper, Category: Command Line
https://github.com/remobjects/ElementsSamples/tree/master/Hydrogene/Cooper/Command Line/Mandelbrot

  • Mandelbrot
    • References
      • rt
    • Source Files
    • Other Files

Program.cs

namespace org.me.mandelbrot
{

	/*
	This example demonstrates using varying density characters to render the
	Mandelbrot set out to stdout
	*/

	public class ConsoleApp
	{
		public static void Main(String[] args)
		{
			const int cols = 78;
			const int lines = 30;
			const String chars = " .,`':;=|+ihIHEOQSB#$";
			const int maxIter = length(chars);

			var minRe = -2.0;
			var maxRe = 1.0;
			var minIm = -1.0;
			var maxIm = 1.0;
			var im = minIm;
			while (im <= maxIm)
			{
				var re = minRe;
				while (re <= maxRe)
				{
					var zr = re;
					var zi = im;
					var n = -1;
					while (n < maxIter-1)
					{
						n++;
						var a = zr * zr; 
						var b = zi * zi;
						if (a + b > 4.0)
						  break;
						zi = 2 * zr * zi + im;
						zr = a - b + re;
					}
					System.@out.print(chars[n]);
					re += (maxRe - minRe) / cols;
				}
				writeLn();
				im += (maxIm - minIm) / lines;
			}
			
			//Press ENTER to continue
			System.@out.println("Press ENTER to exit");
			System.@in.read();
		}
	}
}