private bool Iterate(complex c, double p) { var z = new complex(.0d, .0d); for (int i = 0; i < 50; i++) { var r = (polar)z; r = r.Pow(p); z = (complex)r + c; if (z.Abs2() > 4.0d) { return(false); } } return(z.Abs2() < 4.0d); }
private void Launch(double p, int?n = null) { var w = Convert.ToDouble(panel1.Width); var h = Convert.ToDouble(panel1.Height); var rh = 3.0 / h; Graphics g = null; Bitmap bm = null; var save = n.HasValue; if (!save) { g = panel1.CreateGraphics(); } else { bm = new Bitmap(1080, 1080, System.Drawing.Imaging.PixelFormat.Format32bppArgb); w = h = 1080d; rh = 3.0 / 1080d; g = Graphics.FromImage(bm); } g.Clear(Color.White); var hdc = g.GetHdc(); for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { var a = 1.0 - (w - (double)x) * rh; var b = 1.5 - ((double)y) * rh; var z = new complex(a, b); var r = Iterate(z, p); if (r) { GDI.SetPixel(hdc, x, y, 0x00000000); } } } g.ReleaseHdc(hdc); g.DrawString(p.ToString("0.000"), SystemFonts.DefaultFont, Brushes.Black, 50, 50); if (save) { bm.Save($@"d:\brol\mb\mb{n.Value.ToString("d4")}.png", ImageFormat.Png); Invoke(new MethodInvoker(delegate { var g2 = panel1.CreateGraphics(); g2.DrawImage(bm, new Point(0, 0)); g2.Dispose(); bm.Dispose(); })); } g.Dispose(); }