示例#1
0
            internal bool Compare(ColorCell cell, int threshold)
            {
                if (IsAllTransparnet || cell.IsAllTransparnet)
                {
                    return(IsAllTransparnet && cell.IsAllTransparnet);
                }
                if (Collors.Length != cell.Collors.Length)
                {
                    return(false);
                }

                for (int i = 0; i < Collors.Length; ++i)
                {
                    int diff = 0;
                    diff += Mathf.Abs(Collors[i].r - cell.Collors[i].r);
                    diff += Mathf.Abs(Collors[i].g - cell.Collors[i].g);
                    diff += Mathf.Abs(Collors[i].b - cell.Collors[i].b);
                    diff += Mathf.Abs(Collors[i].a - cell.Collors[i].a);
                    if (diff > threshold)
                    {
                        return(false);
                    }
                }
                return(true);
            }
示例#2
0
            void MakeCells(DicingTextures target)
            {
                this.IsNoneAlpha = true;

                int atlasCellSize   = target.CellSize;
                int textureCellSize = target.CellSize - target.Padding * 2;
                int padding         = target.Padding;

                //テクスチャの全カラー情報
                Color32[] textureColors = texture.GetPixels32();

                int cellCountX = Mathf.CeilToInt(1.0f * Width / textureCellSize);
                int cellCountY = Mathf.CeilToInt(1.0f * Height / textureCellSize);

                this.cells = new ColorCell[cellCountX, cellCountY];
                for (int cellX = 0; cellX < cellCountX; ++cellX)
                {
                    int x = cellX * textureCellSize;
                    for (int cellY = 0; cellY < cellCountY; ++cellY)
                    {
                        int y = cellY * textureCellSize;
                        Profiler.BeginSample("GetPixels32");
                        ColorCell cell = MakeCell(textureColors, x - padding, y - padding, atlasCellSize, atlasCellSize);
                        this.cells[cellX, cellY] = cell;
                        Profiler.EndSample();
                        Profiler.BeginSample("new ColorCell");
                        Profiler.EndSample();
                        if (!cell.IsNoneAlpha)
                        {
                            this.IsNoneAlpha = false;
                        }
                    }
                }
            }
示例#3
0
 /// <summary>
 /// Конструктор по умолчанию
 /// </summary>
 /// <param name="grid">сетка, по которой передвигается робот</param>
 /// <param name="robot">робот</param>
 /// <param name="pouringColor">цвет заливки ячейки, в которой находится робот</param>
 public PouringCellCommand(Grid grid, Robot robot, ColorCell pouringColor)
 {
     Grid          = grid;
     Robot         = robot;
     _pouringColor = pouringColor;
     Execute       = PouringCell;
 }
示例#4
0
            internal bool Compare(ColorCell cell)
            {
                if (IsAllTransparnet || cell.IsAllTransparnet)
                {
                    return(IsAllTransparnet && cell.IsAllTransparnet);
                }
                if (Collors.Length != cell.Collors.Length)
                {
                    return(false);
                }

                for (int i = 0; i < Collors.Length; ++i)
                {
                    if (Collors[i].r != cell.Collors[i].r)
                    {
                        return(false);
                    }
                    if (Collors[i].g != cell.Collors[i].g)
                    {
                        return(false);
                    }
                    if (Collors[i].b != cell.Collors[i].b)
                    {
                        return(false);
                    }
                    if (Collors[i].a != cell.Collors[i].a)
                    {
                        return(false);
                    }
                }
                return(true);
            }
    public virtual void InitializeColorCell(PaintByNumbers reference, int num)
    {
        if (pbn == null)
        {
            pbn = reference;
        }

        colorCell = new ColorCell(num);
    }
示例#6
0
            //指定の矩形のカラー配列を取得
            ColorCell MakeCell(Color32[] textureColors, int x0, int y0, int cellSizeW, int cellSizeH)
            {
                bool      isAllTransParent = true;
                bool      isNoneAlpha      = true;
                ColorCell cell             = new ColorCell();
                int       cellCount        = cellSizeW * cellSizeH;

                Color32[] colors = null;
                for (int y1 = 0; y1 < cellSizeH; ++y1)
                {
                    int y = y0 + y1;
                    for (int x1 = 0; x1 < cellSizeW; ++x1)
                    {
                        int x = x0 + x1;
                        if (x < 0 || y < 0 || x >= Width || y >= Height)
                        {
                        }
                        else
                        {
                            bool alphaZero = (textureColors[x + y * Width].a == 0);
                            isAllTransParent &= alphaZero;
                            isNoneAlpha      &= !alphaZero;
                            if (!isAllTransParent && !isNoneAlpha)
                            {
                                break;
                            }
                        }
                    }
                    if (!isAllTransParent && !isNoneAlpha)
                    {
                        break;
                    }
                }
                if (!isAllTransParent)
                {
                    colors = new Color32[cellCount];
                    int index = 0;
                    for (int y1 = 0; y1 < cellSizeH; ++y1)
                    {
                        int y = Mathf.Clamp(y0 + y1, 0, Height - 1);
                        for (int x1 = 0; x1 < cellSizeW; ++x1)
                        {
                            int x = Mathf.Clamp(x0 + x1, 0, Width - 1);
                            colors[index] = textureColors[x + y * Width];
                            ++index;
                        }
                    }
                }
                cell.IsNoneAlpha      = isNoneAlpha;
                cell.IsAllTransparnet = isAllTransParent;
                cell.Collors          = colors;
                return(cell);
            }
示例#7
0
        public void testRule2()
        {
            //test with 2 neighbors
            GeneticLife test     = new GeneticLife(2);
            ColorCell   testCell = test.GetCell(0, 0);

            testCell.IsAlive = true;
            testCell.red     = Byte.MaxValue / 2;
            testCell.green   = Byte.MaxValue / 2;
            testCell.blue    = Byte.MaxValue / 2;

            test.GetCell(0, 1).IsAlive = true;
            test.GetCell(0, 1).red     = Byte.MaxValue;
            test.GetCell(1, 0).IsAlive = true;
            test.GetCell(1, 0).blue    = Byte.MaxValue;
            test.GetCell(1, 1).IsAlive = false;
            test.Iterate();

            Assert.IsTrue(test.GetCell(0, 0).IsAlive);
            Assert.AreEqual(Byte.MaxValue / 2, testCell.red);
            Assert.AreEqual(Byte.MaxValue / 2, testCell.green);
            Assert.AreEqual(Byte.MaxValue / 2, testCell.blue);

            //test with 3 neighbors
            test             = new GeneticLife(2);
            testCell         = test.GetCell(0, 0);
            testCell.IsAlive = true;
            testCell.red     = Byte.MaxValue / 2;
            testCell.green   = Byte.MaxValue / 2;
            testCell.blue    = Byte.MaxValue / 2;

            test.GetCell(0, 1).IsAlive = true;
            test.GetCell(0, 1).red     = Byte.MaxValue;
            test.GetCell(1, 0).IsAlive = true;
            test.GetCell(1, 0).blue    = Byte.MaxValue;
            test.GetCell(1, 1).IsAlive = true;
            test.Iterate();

            Assert.IsTrue(test.GetCell(0, 0).IsAlive);
            Assert.AreEqual(Byte.MaxValue / 2, testCell.red);
            Assert.AreEqual(Byte.MaxValue / 2, testCell.green);
            Assert.AreEqual(Byte.MaxValue / 2, testCell.blue);
        }
示例#8
0
        /// <summary>
        /// Метод закрашивающий выбранным цветом ячейку
        /// </summary>
        /// <param name="row">индекс строки ячейки</param>
        /// <param name="column">индекс столбца ячейки</param>
        /// <param name="color">цвет заливки</param>
        public void UpdateColorCell(ColorCell color, int row, int column)
        {
            switch (color)
            {
            case ColorCell.Black:
                grid.VisualCells[row, column].Fill = new SolidColorBrush {
                    Color = Colors.Black
                };
                break;

            case ColorCell.White:
                grid.VisualCells[row, column].Fill = new SolidColorBrush {
                    Color = Colors.White
                };
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(color), color, null);
            }
        }
示例#9
0
        public void testRule4()
        {
            GeneticLife test     = new GeneticLife(2);
            ColorCell   testCell = test.GetCell(0, 0);

            testCell.IsAlive           = false;
            test.GetCell(0, 1).IsAlive = true;
            initializeSimpleColors(test.GetCell(0, 1));
            test.GetCell(0, 1).IsAlive = true;
            initializeSimpleColors(test.GetCell(1, 0));
            test.GetCell(1, 0).IsAlive = true;
            initializeSimpleColors(test.GetCell(1, 1));
            test.GetCell(1, 1).IsAlive = true;
            test.Iterate();

            testCell = test.GetCell(0, 0);
            Assert.IsTrue(testCell.IsAlive);
            Assert.AreEqual(testCell.red, 1);
            Assert.AreEqual(testCell.green, 2);
            Assert.AreEqual(testCell.blue, 3);
        }
示例#10
0
            //アトラス画像に新たなテクスチャを追加してみる
            internal bool TryAddTexture(TextureInfo texture, out List <ColorCell> newCells, out List <int> indexList)
            {
                indexList = new List <int>();
                newCells  = new List <ColorCell>();

                int textureCellSize = CellSize - Padding * 2;
                int cellCountX      = Mathf.CeilToInt(1.0f * texture.Width / textureCellSize);
                int cellCountY      = Mathf.CeilToInt(1.0f * texture.Height / textureCellSize);

                for (int cellY = 0; cellY < cellCountY; ++cellY)
                {
                    for (int cellX = 0; cellX < cellCountX; ++cellX)
                    {
                        ColorCell cell = texture.GetCell(cellX, cellY);
                        //アトラス内のセルリストと比較
                        int cellIndex = cells.FindIndex(item => (item.Compare(cell)));
                        if (cellIndex < 0)
                        {
                            //新しいセルリストと比較
                            cellIndex = newCells.FindIndex(item => (item.Compare(cell)));
                            if (cellIndex < 0)
                            {
                                //新しいセルリストにもないので新規セルを作成
                                if (!CheckNewCellCount(newCells.Count + 1))
                                {
                                    //アトラス画像に入りきらない
                                    return(false);
                                }
                                cellIndex = newCells.Count;
                                newCells.Add(cell);
                            }
                            cellIndex += cells.Count;
                        }
                        indexList.Add(cellIndex);
                    }
                }
                return(true);
            }
示例#11
0
 /// <summary>
 /// Конструктор по умолчанию
 /// </summary>
 /// <param name="color">цвет ячейки</param>
 /// <param name="isMove">если true - ячейка проходима, если false - ячейка не проходима</param>
 public Cell(ColorCell color, bool isMove)
 {
     Color  = color;
     IsMove = isMove;
 }
示例#12
0
            //アトラスの画像を作成
            internal Texture2D MakeAtlasTexture()
            {
                InitAtlasSize();
                Texture2D texture = new Texture2D(Width, Height);

                this.IsNoneAlpha = true;
                foreach (var cell in cells)
                {
                    if (!cell.IsNoneAlpha)
                    {
                        IsNoneAlpha = false;
                        break;
                    }
                }

                //デフォルト(書き込みをしない)色
                Color32[] defaultColorArray = new Color32[CellSize * CellSize];
                byte      alpha             = IsNoneAlpha ? byte.MaxValue : byte.MinValue;
                Color32   defaultColor      = new Color32(0, 0, 0, alpha);

                for (int i = 0; i < defaultColorArray.Length; ++i)
                {
                    defaultColorArray[i] = defaultColor;
                }

                //
                int cellIndex = 0;

                for (int y = 0; y < Height; y += CellSize)
                {
                    for (int x = 0; x < Width; x += CellSize)
                    {
                        try
                        {
                            if (cellIndex >= cells.Count)
                            {
                                //セルの登録がない場合完全に透明
                                texture.SetPixels32(x, y, CellSize, CellSize, defaultColorArray);
                            }
                            else
                            {
                                ColorCell cell = cells[cellIndex];
                                if (cell.IsAllTransparnet)
                                {
                                    //セルの登録がない場合完全に透明
                                    texture.SetPixels32(x, y, CellSize, CellSize, defaultColorArray);
                                }
                                else
                                {
                                    texture.SetPixels32(x, y, CellSize, CellSize, cell.Collors);
                                }
                                ++cellIndex;
                            }
                        }
                        catch (System.Exception e)
                        {
                            Debug.LogError(e.Message);
                        }
                    }
                }
                texture.Apply();
                if (cells.Count != cellIndex)
                {
                    Debug.Log("");
                }
                return(texture);
            }
示例#13
0
 public void Add(ColorCell cell)
 {
     cells.Add(cell);
 }
示例#14
0
        //Dictionary<int, Color> NumColor = new Dictionary<int, Color>();


        /*  public Cell()
         * {
         *    NumColor.Add(0, Color.Blue);
         *    NumColor.Add(1, Color.Green);
         *    NumColor.Add(2, Color.Orange);
         *    NumColor.Add(3, Color.Pink);
         *    NumColor.Add(4, Color.Red);
         *    NumColor.Add(5, Color.White);
         *
         * }*/
        public void ChangeColotInt(int n)
        {
            this.GetColor = (ColorCell)n;
        }
示例#15
0
 private void initializeSimpleColors(ColorCell cell)
 {
     cell.red   = 1;
     cell.green = 2;
     cell.blue  = 3;
 }