예제 #1
0
 public NoiseLoop(float d, float min, float max)
 {
     Diameter = d;
     Min      = min;
     Max      = max;
     CenterX  = PMath.Random(1000);
     CenterY  = PMath.Random(1000);
 }
예제 #2
0
        public void Setup()
        {
            StartImage = PSprite.FromFilePath(StartImagePath);
            EndImage   = PSprite.FromFilePath(EndImagePath);

            if (Count)
            {
                var startCount = 0;
                var endCount   = 0;

                for (var y = 0; y < Height; y++)
                {
                    for (var x = 0; x < Width; x++)
                    {
                        if (StartImage.Art.GetPixel(x, y).A > 0)
                        {
                            startCount++;
                        }
                        if (EndImage.Art.GetPixel(x, y).A > 0)
                        {
                            endCount++;
                        }
                    }
                }

                Console.WriteLine("Start: " + startCount);
                Console.WriteLine("End: " + endCount);
                Console.ReadLine();

                return;
            }

            var startPixels = StartImage.Art.GetPixels();

            AvailablePositions = new OrderedDictionary();
            pixels             = new List <Pixel>(Width * Height);

            CalculateStart(Width, Height);

            var imagePixels = EndImage.Art.GetPixels();

            var totalDone = 0;

            var width      = Width;
            var height     = Height;
            var generating = false;
            var count      = 0;

            var distance = 0;

            for (var y = 0; y < height; y++)
            {
                for (var x = 0; x < width; x++)
                {
                    var b = (x + (y * width)) * 4;
                    var c = PColor.FromPixels(imagePixels, b);

                    if (c.A > 0)
                    {
                        if (AvailablePositions.Count == 0)
                        {
                            if (generating)
                            {
                                while (generating)
                                {
                                }
                                goto b;
                            }

                            generating = true;
                            CalculateStart(width, height);
                            generating = false;
                        }

                        b :;

                        var pos = (-1, -1);

                        distance -= 2;
                        if (distance < 0)
                        {
                            distance = 0;
                        }
                        goto endWhile; // To Skip
                        do
                        {
                            //for (var y2 = y - distance; y2 < y + distance + 1; y2++)
                            //{
                            //    for (var x2 = x - distance; x2 < x + distance + 1; x2++)
                            //    {
                            //        if (x2 > 0 && x2 < width && y2 > 0 && y2 < height)
                            //        {
                            //            pos = Check(x2, y2);
                            //            if (pos != (-1, -1)) { goto endWhile; }
                            //        }
                            //    }
                            //}

                            for (var y2 = (int)PMath.Clamp(y - distance, 0, height - 1); y2 < (int)PMath.Clamp(y + distance + 1, 0, height - 1); y2++)
                            {
                                var minus   = (int)PMath.Clamp(x - distance, 0, width - 1);
                                var tempPos = (minus, y2);
                                pos = Available2[minus, y2] ? tempPos : (-1, -1);
                                if (pos != (-1, -1))
                                {
                                    goto endWhile;
                                }

                                var plus = (int)PMath.Clamp(x + distance, 0, width - 1);
                                tempPos = (plus, y2);
                                pos     = Available2[plus, y2] ? tempPos : (-1, -1);
                                if (pos != (-1, -1))
                                {
                                    goto endWhile;
                                }
                            }

                            for (var x2 = (int)PMath.Clamp(x - distance, 0, width - 1); x2 < (int)PMath.Clamp(x + distance + 1, 0, width - 1); x2++)
                            {
                                var minus   = (int)PMath.Clamp(y - distance, 0, height - 1);
                                var tempPos = (x2, minus);
                                pos = Available2[x2, minus] ? tempPos : (-1, -1);
                                if (pos != (-1, -1))
                                {
                                    goto endWhile;
                                }

                                var plus = (int)PMath.Clamp(y + distance, 0, height - 1);
                                tempPos = (x2, plus);
                                pos     = Available2[x2, plus] ? tempPos : (-1, -1);
                                if (pos != (-1, -1))
                                {
                                    goto endWhile;
                                }
                            }

                            if (distance > width)
                            {
                                CalculateStart(width, height);
                                distance = 0;
                            }

                            distance++;
                        }while (pos == (-1, -1));
                        endWhile :;
                        pos = ((int, int))AvailablePositions[0];
                        AvailablePositions.RemoveAt(0);

                        //AvailablePositions.Remove(pos);

                        Available2[pos.Item1, pos.Item2] = false;
                        var b2 = (pos.Item1 + (pos.Item2 * width)) * 4;

                        pixels.Add(new Pixel()
                        {
                            StartColor = PColor.FromPixels(startPixels, b2), EndColor = c, StartPos = pos, EndPos = (x, y), Offset = PMath.Random(0, Offset)
                        });