static void RenderPart(FractalConfig conf, int x, int y, int wth, int hth, IDensityMatrix data, Complex pert) { //http://www.physics.emory.edu/faculty/weeks/software/mandel.c Complex z, c; InitZC(conf, x, y, wth, hth, pert, out z, out c); Complex[] points = new Complex[conf.IterMax]; int escapeiter = FillOrbit(points, conf.IterMax, z, c, conf.Escape, out bool didesc); bool hide = conf.HideEscaped && didesc || conf.HideContained && !didesc; if (hide) { return; } for (int iter = 0; iter < escapeiter; iter++) { Complex f = points[iter]; int bx = WorldToWin(f.Real, conf.Resolution, wth, conf.OffsetX); int by = WorldToWin(f.Imaginary, conf.Resolution, hth, conf.OffsetY); if (bx >= 0 && bx < wth && by >= 0 && by < hth) { data.Touch(bx, by); } } }
static void DrawToImageComponent(ICanvas img, IDensityMatrix matrix, ColorComponent comp) { Logger.PrintInfo("matrix = [" + matrix.Width + "x" + matrix.Height + " " + matrix.Maximum + "]"); IColorMap cm = new GrayColorMap(); Logger.PrintInfo("drawing component '" + comp + "'"); PaintImageData(matrix, cm, img, comp); }
static void DoCreateImage(IDensityMatrix matrix) { Logger.PrintInfo("matrix = [" + matrix.Width + "x" + matrix.Height + " " + matrix.Maximum + "]"); IColorMap cm = GetColorMap(out string _); using (var img = new MagicCanvas(Options.Width, Options.Height)) { Logger.PrintInfo("building image"); PaintImageData(matrix, cm, img); SaveCanvas(img); } }
public FractalBuilder(IDensityMatrix matrix, FractalConfig config = null) { Matrix = matrix; this.config = config ?? FractalConfig.Default; }
static void PaintImageData(IDensityMatrix matrix, IColorMap cm, ICanvas img, ColorComponent comp = ColorComponent.None) { double lm = matrix.Maximum; // find minimum method double ln = double.MaxValue; for (int y = 1; y < Options.Height - 1; y++) { for (int x = 1; x < Options.Width - 1; x++) { double li = matrix[x, y]; if (li > 0.0 && li < ln) { ln = li; } } } Debug.WriteLine("ln = " + ln); //chop at most frequent value //double hmax = 0.0; //int cmax = 0; //var histogram = new Dictionary<double,int>(); //for (int y = 1; y < Options.Height - 1; y++) { // for (int x = 1; x < Options.Width - 1; x++) { // double li = matrix[x, y]; // if (li < double.Epsilon || double.IsInfinity(li) || double.IsNaN(li)) { continue; } // if (!histogram.TryGetValue(li,out int val)) { // val = 1; // } else { // val++; // } // if (val > cmax) { // cmax = val; // hmax = li; // } // histogram[li] = val; // } //} // Debug.WriteLine("hmax = "+hmax+" cmax = "+cmax); //find minimum method using average of blocks //double ln = double.MaxValue; //int aspect = 32; //int aw = (Options.Width - 1) / aspect; //int ah = (Options.Height - 1) / aspect; //for (int ay = 1; ay < ah; ay++) { // for (int ax = 1; ax < aw; ax++) { // int ys = ay * aspect; int ye = ys + aspect - 1; // int xs = ax * aspect; int xe = xs + aspect - 1; // double avg = 0.0; // for(int y = ys; y < ye; y++) { // for(int x = xs; x < xe; x++) { // if (x >= 0 && x < Options.Width && y >=0 && y < Options.Height) { // double li = matrix[x, y]; // avg += li; // } // } // } // avg /= (aspect * aspect); // if (avg > 0.0 && avg < ln) { ln = avg; } // } //} //Debug.WriteLine("ln = "+ln); //find average method //double total = 0.0; //long count = 0; //for (int y = 1; y < Options.Height - 1; y++) { // for (int x = 1; x < Options.Width - 1; x++) { // double li = matrix[x, y]; // if (li >= 0.0 && !double.IsInfinity(li) && !double.IsNaN(li)) { // total += li; // count++; // } // } //} //double ln = total / count; //Debug.WriteLine("ln = "+ln); for (int y = 0; y < Options.Height; y++) { for (int x = 0; x < Options.Width; x++) { double li = matrix[x, y]; ColorD c = cm.GetColor(li - ln, lm - ln); if (comp != ColorComponent.None) { img.SetPixelComponent(x, y, comp, c.GetComponent(comp)); } else { img.SetPixel(x, y, c); } } } }