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: Silver, Platform: Echoes, Category: Command Line
https://github.com/remobjects/ElementsSamples/tree/master/Silver/Echoes/Command Line/Mandelbrot

  • Mandelbrot
    • References
      • mscorlib
      • Swift
    • Source Files
    • Other Files

Program.swift

let cols = 78
let lines = 30

var chars = [" ",".",",","`","'",":","=","|","+","i","h","I","H","E","O","Q","S","B","#","$"]

let maxIter = count(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 += 1
			var a = zr * zr
			var b = zi * zi
			if a + b > 4.0 { break }
			zi = 2 * zr * zi + im
			zr = a - b + re
		}
		print(chars[n], separator: "", terminator: "")
		re += (maxRe - minRe) / Double(cols)
	}
	print()
	im += (maxIm - minIm) / Double(lines)
}