Exemplo n.º 1
0
        public static SitesList GenerateSites(int p_Seed, int p_Dimension, int p_Sites, double p_MinimumSpread)
        {
            SitesList l_result = null;

            List <PointD> l_list = new List <PointD>();

            Random l_r = new Random(p_Seed);

            for (int i = 0; i < p_Sites; ++i)
            {
                do
                {
                    double l_X = l_r.NextDouble() * p_Dimension;
                    double l_Y = l_r.NextDouble() * p_Dimension;
                    PointD l_p = new PointD(l_X, l_Y);

                    if (l_list.Count == 0)
                    {
                        l_list.Add(l_p);
                    }
                    else
                    {
                        if (DistanceToNearestNeighbour(l_p, ref l_list) >= p_MinimumSpread)
                        {
                            l_list.Add(l_p);
                            break;
                        }
                    }
                }while (true);
            }

            l_result = new SitesList(p_Dimension, l_list);

            return(l_result);
        }
Exemplo n.º 2
0
        public static Image RenderSitesList(SitesList p_List)
        {
            Bitmap   l_Bitmap = new Bitmap(p_List.Dimension, p_List.Dimension);
            Image    l_Image  = (Image)l_Bitmap;
            Graphics l_g      = Graphics.FromImage(l_Image);

            l_g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            for (int i = 0; i < p_List.Sites.Count; ++i)
            {
                DrawCross(
                    l_g,
                    Pens.Blue,
                    p_List.Sites[i],
                    2);
            }

            return(l_Image);
        }
Exemplo n.º 3
0
        private void m_Generate_Click(object sender, EventArgs e)
        {
            int l_Sites      = 10;
            int l_Dimensions = 512;
            int l_Seed       = 0;

            if (IntValueFromTextBox(m_Seed, out l_Seed))
            {
                if (IntValueFromTextBox(m_Dimension, out l_Dimensions))
                {
                    if (IntValueFromTextBox(m_Sites, out l_Sites))
                    {
                        SitesList l_SitesList = Generators.GenerateSites(l_Seed, l_Dimensions, l_Sites, 12);

                        m_Preview.BackgroundImage       = GraphicHelpers.RenderSitesList(l_SitesList);
                        m_Preview.BackgroundImageLayout = ImageLayout.None;
                    }
                }
            }
        }