protected int RenderArtificialLife(Pixbuf pixbuf, ArtificialLife artificialLife, int x, int y, bool Clear = true)
    {
        var Updates = 0;

        if (pixbuf != null && artificialLife != null)
        {
            var writeBuffer = artificialLife.GetPixelWriteBuffer();

            Updates += writeBuffer.Count;

            if (writeBuffer.Count > 0)
            {
                Parallel.ForEach(writeBuffer, (pixel) =>
                {
                    pixel.Write(pixbuf, x, y);
                });

                if (Clear)
                {
                    artificialLife.ClearPixelWriteBuffer();
                }
            }
        }

        return(Updates);
    }
Beispiel #2
0
    public Colony()
    {
        X = 0;
        Y = 0;

        ArtificialLife = new EmptyArtificialLife();
    }
Beispiel #3
0
    public Colony(int x, int y, ArtificialLife artificialLife)
    {
        X = x;
        Y = y;

        ArtificialLife = artificialLife;
    }
    public static void Draw(Pixbuf pixbuf, int Width, int Height, ArtificialLife colony, int MaxStates, ref int population)
    {
        population = 0;

        double delta = Math.Ceiling((double)256 / MaxStates);

        for (int y = 0; y < Height; y++)
        {
            for (int x = 0; x < Width; x++)
            {
                var offset = pixbuf.Pixels + y * pixbuf.Rowstride + x * pixbuf.NChannels;

                var r = Marshal.ReadByte(offset);
                var g = r;
                var b = r;

                if (pixbuf.NChannels > 1)
                {
                    g = Marshal.ReadByte(offset + 1);
                }

                if (pixbuf.NChannels > 2)
                {
                    b = Marshal.ReadByte(offset + 2);
                }

                var val = (int)((double)(r * 299 + g * 587 + b * 114) / 1000);

                if (colony is Life)
                {
                    (colony as Life).WriteCell(x, y, val);

                    population += val > 0 ? 1 : 0;
                }

                if (colony is YinYangFire)
                {
                    var value = (int)(val / delta);

                    (colony as YinYangFire).WriteCell(x, y, value);

                    population += value > 0 ? 1 : 0;
                }

                if (colony is Zhabotinsky)
                {
                    (colony as Zhabotinsky).WriteCell(x, y, val);

                    population += val > 0 ? 1 : 0;
                }

                if (colony is LangtonAnt)
                {
                    var value = (int)(val / delta);

                    (colony as LangtonAnt).WriteCell(x, y, value);
                }

                if (colony is ForestFire)
                {
                    (colony as ForestFire).WriteCell(x, y, Math.Max(3, val));

                    population += val & 1;
                }

                if (colony is Ice)
                {
                    (colony as Ice).WriteCell(x, y, Math.Max(3, val));

                    population += val & 1;
                }

                if (colony is Snowflake)
                {
                    var value = (int)(val / delta);

                    (colony as Snowflake).WriteCell(x, y, value);

                    population += val > 0 ? 1 : 0;
                }

                if (colony is Cyclic)
                {
                    var value = (int)(val / delta);

                    (colony as Cyclic).WriteCell(x, y, value);

                    population += value > 0 ? 1 : 0;
                }
            }
        }
    }