Exemple #1
0
        public static Generator Filter(this Generator gen, params FilterType[] types)
        {
            foreach (var type in types)
            {
                var tempGen = gen;
                switch (type)
                {
                case FilterType.Invert:
                    gen = new Function(
                        x => 1 - tempGen.Get(x),
                        xy => 1 - tempGen.Get(xy),
                        xyz => 1 - tempGen.Get(xyz));
                    break;

                case FilterType.Billow:
                    gen = new Function(
                        x => Maths.Abs((2 * tempGen.Get(x)) - 1),
                        xy => Maths.Abs((2 * tempGen.Get(xy)) - 1),
                        xyz => Maths.Abs((2 * tempGen.Get(xyz)) - 1));
                    break;

                case FilterType.Ridged:
                    gen = gen.Filter(FilterType.Billow, FilterType.Invert);
                    break;

                case FilterType.Sin:
                    gen = new Function(
                        x => (Maths.Sin(2 * math.PI * tempGen.Get(x)) / 2) + .5f,
                        xy => (Maths.Sin(2 * math.PI * tempGen.Get(xy)) / 2) + .5f,
                        xyz => (Maths.Sin(2 * math.PI * tempGen.Get(xyz)) / 2) + .5f);
                    break;

                case FilterType.Asin:
                    gen = new Function(
                        x => (Maths.Asin((2 * tempGen.Get(x)) - 1) / math.PI) + .5f,
                        xy => (Maths.Asin((2 * tempGen.Get(xy)) - 1) / math.PI) + .5f,
                        xyz => (Maths.Asin((2 * tempGen.Get(xyz)) - 1) / math.PI) + .5f);
                    break;

                case FilterType.Atan:
                    gen = new Function(
                        x => (2 * Maths.Atan((2 * tempGen.Get(x)) - 1) / math.PI) + .5f,
                        xy => (2 * Maths.Atan((2 * tempGen.Get(xy)) - 1) / math.PI) + .5f,
                        xyz => (2 * Maths.Atan((2 * tempGen.Get(xyz)) - 1) / math.PI) + .5f);
                    break;

                case FilterType.Tanh:
                    gen = new Function(
                        x => 2 * Maths.Tanh(2 * tempGen.Get(x) - 1) / 2 + .5f,
                        xy => 2 * Maths.Tanh(2 * tempGen.Get(xy) - 1) / 2 + .5f,
                        xyz => 2 * Maths.Tanh(2 * tempGen.Get(xyz) - 1) / 2 + .5f);
                    break;

                default:
                    throw new ArgumentException($"Invalid filter type: '{type.ToString()}'");
                }
            }

            return(gen);
        }