Ejemplo n.º 1
0
        public void Setup()
        {
            ArrWidth  = (Width / Rez) + 1;
            ArrHeight = (Height / Rez) + 1;
            Map       = new float[ArrWidth, ArrHeight];

            for (var y = 0; y < ArrHeight; y++)
            {
                for (var x = 0; x < ArrWidth; x++)
                {
                    //Map[x, y] = (float)r.NextDouble();
                    Map[x, y] = PMath.Clamp(noise.GetPerlin(x * PMath.PI, y * PMath.PI, z) + 0.5f, 0, 1);
                }
            }

            AddKeyAction("W", (d) =>
            {
                if (!d)
                {
                    return;
                }
                Thresh *= 1.05f;
                Thresh  = PMath.Clamp(Thresh, 0, 1);
            });
            AddKeyAction("S", (d) =>
            {
                if (!d)
                {
                    return;
                }
                Thresh *= 0.95f;
                Thresh  = PMath.Clamp(Thresh, 0, 1);
            });
        }
Ejemplo n.º 2
0
        public PColor Convert(PColor i)
        {
            i.G -= (int)(i.R * 0.67f);
            i.G  = (int)PMath.Clamp(i.G, 0, 255);

            i.B -= (int)(i.R * 0.33f);
            i.B  = (int)PMath.Clamp(i.B, 0, 255);

            i.R = 0;

            RgbToHls(i.R, i.G, i.B, out var h, out var l, out var s);

            //h = PMath.Clamp((float)h, 70, 300);
            //h = PMath.Map((float)h, 0, 360, 20, 280);
            l = PMath.Clamp((float)l, 0f, 0.3f);
            //l = PMath.Map((float)l, 0f, 0.3f, 0f, 1f);

            HlsToRgb(h, l, s, out i.R, out i.G, out i.B);

            return(new PColor((int)PMath.Map(i.R, 0, 255, 0, i.G + i.B), i.G, i.B));
        }
Ejemplo n.º 3
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)
                        });
Ejemplo n.º 4
0
        public void Draw(float delta)
        {
            z += delta * 50;

            for (var y = 0; y < ArrHeight; y++)
            {
                for (var x = 0; x < ArrWidth; x++)
                {
                    //Map[x, y] = (float)r.NextDouble();
                    Map[x, y] = PMath.Clamp(noise.GetPerlin(x * PMath.PI, y * PMath.PI, z) + 0.5f, 0, 1);
                }
            }

            Title(Thresh);
            Art.Background(PColor.Grey);
            Art.NoStroke();

            for (var y = 0; y < ArrHeight; y++)
            {
                for (var x = 0; x < ArrWidth; x++)
                {
                    Art.Fill(new PColor((int)(Map[x, y] * 200)));
                    Art.Rect(x * Rez, y * Rez, Rez + 1, Rez + 1);
                    //Art.Circle(x * Rez, y * Rez, Rez * 0.55f);
                }
            }

            Art.NoFill();
            Art.Stroke(PColor.Black);
            Art.StrokeWeight(2);

            for (var y = 0f; y < ArrHeight - 1; y++)
            {
                for (var x = 0f; x < ArrWidth - 1; x++)
                {
                    var a = ((x * Rez) + (Rez / 2f), (y * Rez));
                    var b = ((x * Rez) + Rez, (y * Rez) + (Rez / 2f));
                    var c = ((x * Rez) + (Rez / 2f), (y * Rez) + Rez);
                    var d = ((x * Rez), (y * Rez) + (Rez / 2f));



                    var which = 0;
                    if (Map[(int)x, (int)y] > Thresh)
                    {
                        which += 8;
                    }
                    if (Map[(int)x + 1, (int)y] > Thresh)
                    {
                        which += 4;
                    }
                    if (Map[(int)x + 1, (int)y + 1] > Thresh)
                    {
                        which += 2;
                    }
                    if (Map[(int)x, (int)y + 1] > Thresh)
                    {
                        which += 1;
                    }

                    if (which == 4 || which == 10 || which == 11)
                    {
                        Line(a, b);
                    }
                    if (which == 6 || which == 9)
                    {
                        Line(a, c);
                    }
                    if (which == 5 || which == 7 || which == 8)
                    {
                        Line(a, d);
                    }
                    if (which == 2 || which == 5 || which == 13)
                    {
                        Line(b, c);
                    }
                    if (which == 3 || which == 12)
                    {
                        Line(b, d);
                    }
                    if (which == 1 || which == 10 || which == 14)
                    {
                        Line(c, d);
                    }

                    void Line((float, float) one, (float, float) two)
                    {
                        Art.Line(one.Item1, one.Item2, two.Item1, two.Item2);
                    }
                }
            }
        }