/* The Great Computer Language Shootout http://shootout.alioth.debian.org/ contributed by Isaac Gouy */ using System; using System.IO; using System.Runtime.InteropServices; class Mandelbrot { public static void Main(String[] args) { int width = 100; if (args.Length > 0) width = Int32.Parse(args[0]); int height = width, i, m = 50, bits = 0, bitnum = 0; bool isOverLimit = false; double Zr = 0.0, Zi = 0.0, Cr, Ci, Tr, Ti, limit2 = 4.0; Console.WriteLine("P4"); Console.WriteLine("{0} {1}", width,height); #if SLOW Stream s = Console.OpenStandardOutput(1024); #endif for(int y = 0; y < height; y++) { for(int x = 0; x < width; x++){ Zr = 0.0; Zi = 0.0; Cr = 2.0*x / width - 1.5; Ci = 2.0*y / height - 1.0; i = 0; do { Tr = Zr*Zr - Zi*Zi + Cr; Ti = 2.0*Zr*Zi + Ci; Zr = Tr; Zi = Ti; isOverLimit = Zr*Zr + Zi*Zi > limit2; } while (!isOverLimit && (++i < m)); bits = bits << 1; if (!isOverLimit) bits++; bitnum++; if (x == width - 1) { bits = bits << (8 - bitnum); bitnum = 8; } if (bitnum == 8){ #if SLOW s.WriteByte((byte)bits); #else putchar ((byte)bits); #endif bits = 0; bitnum = 0; } } } } #if !SLOW [DllImport ("libc")] static extern int putchar (int data); #endif }