Ejemplo n.º 1
0
        Color GetColour(Color a, Color b, Color c, TileSuperposition tile)
        {
            Color res = new Color();
            float firstTilePercentage   = tile.Superpositions[0] / (float)tile.Sum;
            float secondtTilePercentage = tile.Superpositions[1] / (float)tile.Sum;
            float thirdTilePercentage   = tile.Superpositions[2] / (float)tile.Sum;

            int redValueSum   = (int)((firstTilePercentage * a.R) + (secondtTilePercentage * b.R) + (thirdTilePercentage * c.R));
            int greenValueSum = (int)((firstTilePercentage * a.G) + (secondtTilePercentage * b.G) + (thirdTilePercentage * c.G));
            int blueValueSum  = (int)((firstTilePercentage * a.B) + (secondtTilePercentage * b.B) + (thirdTilePercentage * c.B));

            if (redValueSum > 255)
            {
                redValueSum = 255;
            }
            if (greenValueSum > 255)
            {
                greenValueSum = 255;
            }
            if (blueValueSum > 255)
            {
                blueValueSum = 255;
            }

            if (redValueSum < 0)
            {
                redValueSum = 0;
            }
            if (greenValueSum < 0)
            {
                greenValueSum = 0;
            }
            if (blueValueSum < 0)
            {
                blueValueSum = 0;
            }

            res = Color.FromArgb(redValueSum, greenValueSum, blueValueSum);

            return(res);
        }
Ejemplo n.º 2
0
        // Check the superposition for each place in wave in order to check how many patterns are possible to be placed in each location
        public TileSuperposition[,] GetPossibleTileTypes()
        {
            TileSuperposition[,] uncollapsed = new TileSuperposition[width, height];

            for (int i = 0; i < waveCollapse.GetLength(0); i++)
            {
                for (int j = 0; j < waveCollapse.GetLength(1); j++)
                {
                    for (int m = 0; m < 2; m++)
                    {
                        for (int n = 0; n < 2; n++)
                        {
                            int halfStates  = 0;
                            int fullStates  = 0;
                            int emptyStates = 0;

                            for (int k = 0; k < superpositions[i, j].coefficients.Length; k++)
                            {
                                if (superpositions[i, j].coefficients[k] == true)
                                {
                                    if (patterns[k].MiniTile[m, n] == State.HALF_TILE)
                                    {
                                        halfStates++;
                                    }
                                    else if (patterns[k].MiniTile[m, n] == State.FULL_TILE)
                                    {
                                        fullStates++;
                                    }
                                    else if (patterns[k].MiniTile[m, n] == State.EMPTY)
                                    {
                                        emptyStates++;
                                    }
                                }
                            }
                            TileSuperposition a = new TileSuperposition(halfStates, fullStates, emptyStates);
                            if (i + m > waveCollapse.GetLength(0) - 1)
                            {
                                continue;
                            }
                            if (j + n > waveCollapse.GetLength(1) - 1)
                            {
                                continue;
                            }

                            if (uncollapsed[i + m, j + n] != null)
                            {
                                if (uncollapsed[i + m, j + n].Sum > a.Sum)
                                {
                                    uncollapsed[i + m, j + n] = a;
                                }
                            }
                            else
                            {
                                uncollapsed[i + m, j + n] = a;
                            }
                        }
                    }
                }
            }

            return(uncollapsed);
        }