/// <summary>
        ///     Initializes a new instance of the <see cref="RandomColourStyle" /> class.
        /// </summary>
        /// <param name="from">The first colour to interpolate from.</param>
        /// <param name="to">The second colour to interpolate to.</param>
        /// <param name="position">The position.</param>
        public RandomColourStyle(Colour @from, Colour to, Vector2 position = default(Vector2))
        {
            From     = @from;
            To       = to;
            Position = position;

            float x = (float)Math.Round(position.X, 3);
            float y = (float)Math.Round(position.Y, 3);

            float rand = TileRandom.Random(From.ToArgb() + to.ToArgb(), x, y);

            PositionColour = Colour.Interpolate(From, To, rand);
        }
Beispiel #2
0
        /// <summary>
        ///     Gets the style for the given tile.
        /// </summary>
        /// <param name="tile">The tile.</param>
        /// <param name="styles">The styles to choose from.</param>
        /// <param name="state">The style state associated with the tile.</param>
        /// <returns></returns>
        protected override IStyle GetStyle(TileBase tile, IStyle[] styles, ref object state)
        {
            Debug.Assert(tile != null, "tile != null");
            Debug.Assert(styles != null, "styles != null");

            if (styles.Length < 1)
            {
                return(null);
            }

            Vector2 coords = tile.Centroid.Round(3);

            float random = TileRandom.Random(Seed, coords.X, coords.Y);

            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (random == 1)
            {
                return(styles[styles.Length - 1]);
            }

            return(styles[(int)(random * styles.Length)]);
        }
        /// <summary>
        ///     Gets the style for the given tile.
        /// </summary>
        /// <param name="tile">The tile.</param>
        /// <param name="styles">The styles to choose from.</param>
        /// <param name="state">The style state associated with the tile.</param>
        /// <returns></returns>
        protected override IStyle GetStyle(TileBase tile, IStyle[] styles, ref object state)
        {
            IStyle[] unusedStyles = styles.Except(tile.AdjacentTiles.Values.Select(t => t.Style)).ToArray();

            if (unusedStyles.Length == 0)
            {
                return(base.GetStyle(tile, styles, ref state));
            }

            if (unusedStyles.Length == 1)
            {
                Vector2 coords = tile.Centroid.Round(3);

                float random = TileRandom.Random(Seed, coords.X, coords.Y);

                return(random > (1f / styles.Length)
                    ? unusedStyles[0]
                    : base.GetStyle(tile, styles, ref state));
            }

            return(base.GetStyle(tile, unusedStyles, ref state));
        }