class – Problems plotting Julia sets with C# using Scanner method

I’m trying to plot Julia set using oxyplot in C#. The Julia set in a function of the type f(z)=z^2+c, being c a complex coincide with the boundary of the basin of attraction of infinite (the point which that it succession of iterates converges to infinite).

In order to do this, I have created the class Complejos(Complex)

namespace Complejos
{

public class Complejos
    {
        public Complejos()
        {

        }

        private double real;
        private double imaginario;
        public Complejos(double Real, double Imaginario)
        {
            this.Real = Real;
            this.Imaginario = Imaginario;
        }
        public double Real { get; set; }
        public double Imaginario { get; set; }


        public static Complejos uno = new Complejos(1, 0);
        public static Complejos menosuno = new Complejos(-1, 0);


public static double ModuloComplejo(Complejos z)
        {
            double resultado;
            resultado = Math.Sqrt(Math.Pow(z.Real, 2) + Math.Pow(z.Imaginario, 2));
            return resultado;
        }

public static Complejos Julia(Complejos z, Complejos c)
        {
            Complejos resultado = new Complejos();
            resultado = SumaComplejos(CuadradoComplejos(z), c);
            return resultado;
        }

        public static Complejos JuliaIterada(Complejos z, Complejos c, int iterada)
        {
            int cont = 1;
            Complejos resultado = new Complejos();
            resultado = Julia(z, c);
            while (cont < iterada)
            {
                resultado = Julia(resultado, c);
                cont++;
            }
            return resultado;
        }

}
}

The method “Julia” applies the function f(z)=z^2+c, while the method “JuliaIterada” applies the Julia method iteratively, iterada times.

For plotting the Julia set I am using two method, on one hand the iteration inverse method, which work properly. On ther other hand, the scanner method. This one.

using System.Collections.Generic;
using System.Text;

namespace ComplejosLibreria
{
    public class Escaneado
    {
        Complejos.Complejos origen = new Complejos.Complejos(0, 0);
        public static List<Complejos.Complejos> PasoMalla(Complejos.Complejos origen, int dividido, double altura = 0, double anchura = 0)
        {
            if (anchura == 0 || altura == 0)
            {
                anchura = altura;
            }
            double prueba = dividido;


            double origenX = origen.Real - anchura;

            double origenY = origen.Imaginario + altura;
            double reinicioY = origenY;
            double finalX = origenX + 2 * anchura;
            double finalY = origenY - 2 * altura;
            double pasoX = (finalX - origenX) / prueba;
            double pasoY = (finalY - origenY) / prueba;

            List<Complejos.Complejos> pasoMalla = new List<Complejos.Complejos>();


            int cont = 0;
            int cont1 = 0;

            while (cont < dividido)
            {
                cont++;
                origenX += pasoX;
                origenY = 0;
                cont1 = 0;
                origenY = reinicioY;
                while (cont1 < dividido)
                {

                    Complejos.Complejos malla = new Complejos.Complejos();
                    origenY += pasoY;
                    malla.Real = origenX;
                    malla.Imaginario = origenY;
                    pasoMalla.Add(malla);
                    cont1++;
                }
            }

            return pasoMalla;
        }


        
        public static List<Complejos.Complejos> MallaJulia3(Complejos.Complejos c, double division)
        {
           
            double paso = 6 / division;
            double origenX = c.Real - 3 - paso;
            double finalX = c.Real + 3;
            double origenY = c.Imaginario + 3;
            double finalY = c.Imaginario - 3;

            List<Complejos.Complejos> Malla = new List<Complejos.Complejos>();

            while (origenX < finalX)
            {

                origenX += paso;
                origenY = c.Imaginario + 3;
                while (origenY >= finalY)
                {
                    Complejos.Complejos malla = new Complejos.Complejos();
                    malla.Real = origenX;
                    malla.Imaginario = origenY;
                    Malla.Add(malla);
                    origenY -= paso;

                }
            }
            return Malla;
        }

          
        public static List<Complejos.Complejos> MetodoEscaneado2(Complejos.Complejos c, int iterada, double M, int dividido)
        {
            List<Complejos.Complejos> pasoMalla = new List<Complejos.Complejos>();
            pasoMalla = MallaJulia3(c, dividido);
            List<Complejos.Complejos> mallaJulia = new List<Complejos.Complejos>();
            foreach (Complejos.Complejos item in pasoMalla)
            {

                Boolean prueba;
                prueba = (Complejos.Complejos.ModuloComplejo(Complejos.Complejos.JuliaIterada(item, c, iterada)) < M);
                if (prueba)

                {
                    
                    mallaJulia.Add(item);
                }
            }
            return mallaJulia;
        }



    }
}

Knowing that the Julia set of a function f(z)=z^2+c, is always included in the disk with centre c and radio 3, I have created the method MallaJulia3, which take point in this disk dividing the axis x and axis Y, “division” times. Also, I firstly created the method pasoMallo, which do it the same but with a sqaure centred as the point you wish. So, using “MallaJulia3”, I created the method “MethodEscaneado2”, which applies the function “JuliaIterada” k times, and just takes the point with module(ModuloComplejos) lower than M.

In order to plot this I created this WindowsForms.

using System.Windows.Forms;
using OxyPlot;
using OxyPlot.WindowsForms;
using OxyPlot.Series;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using DocumentFormat.OpenXml.Bibliography;
using OxyPlot.Axes;
using Complejos;

using ComplejosLibreria;



namespace JuliaForms {
  
    public partial class Form1 : Form
    {
        public Form1()
        {
            Complejos.Complejos origen = new Complejos.Complejos(0, 0);
            Complejos.Complejos prueba = new Complejos.Complejos(0.285,-0.01);
            Complejos.Complejos prueba1 = new Complejos.Complejos(0, -0.8);
            Complejos.Complejos prueba2 = new Complejos.Complejos(-1,0);
            Complejos.Complejos prueba3 = new Complejos.Complejos(-0.8,-1.6);


            List<Complejos.Complejos> puntosJulia = new List<Complejos.Complejos>();
  
        
            puntosJulia = ComplejosLibreria.Escaneado.MetodoEscaneado2(prueba3, 15, 1000000000000000000, 100);
      

            InitializeComponent();
            PlotView myPlot = new PlotView();

            var model = new PlotModel { Title = "ScatterSeries" };
            var scatterSeries = new ScatterSeries { MarkerType = MarkerType.Circle };
            var r = new Random(314);
            for (int i = 0; i < puntosJulia.Count; i++)
            {
                var x = puntosJulia(i).Real;
                var y = puntosJulia(i).Imaginario;
                var size = 2.5;
                var colorValue = r.Next(100, 1000);
                scatterSeries.Points.Add(new ScatterPoint(x, y, size, colorValue));
            }

               

                model.Series.Add(scatterSeries);
            model.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = OxyPalettes.Jet(200) });

            myPlot.Model = model;

            //Set up plot for display
            myPlot.Dock = System.Windows.Forms.DockStyle.Bottom;
            myPlot.Location = new System.Drawing.Point(0, 0);
            myPlot.Size = new System.Drawing.Size(500, 500);
            myPlot.TabIndex = 0;

           
           
            
                      
        }
    } 
} ```


So, this work sometimes, for instance using the point prueba2=-1, it plot me this image https://ibb.co/nDZkNhJ. However, sometimes does not return anything. This is due to the method "JuliaIterada", which increase all the points, but theorically it shoul not do this.

So, somebody could explain me how to fix the error.

Thanks in advance.