Exemple #1
0
        double Influence(double cornerRotate, Utility.Vector pos)
        {
            cornerRotate *= Math.PI * 2;
            //var toward = new Utility.Vector(
            //    Math.Cos(cornerRotate),
            //    Math.Sin(cornerRotate));
            var toward = new Utility.Vector();

            if (cornerRotate < Math.PI / 4 || cornerRotate > 7 * Math.PI / 4)
            {
                toward.X = 1;
                toward.Y = Math.Sin(cornerRotate);
            }
            else if (cornerRotate < 3 * Math.PI / 4)
            {
                toward.X = Math.Cos(cornerRotate);
                toward.Y = 1;
            }
            else if (cornerRotate < 5 * Math.PI / 4)
            {
                toward.X = -1;
                toward.Y = Math.Sin(cornerRotate);
            }
            else
            {
                toward.X = Math.Cos(cornerRotate);
                toward.Y = -1;
            }

            return(toward * pos);
        }
Exemple #2
0
        public void GetNoise(double x, double y, ref double res)
        {
            var basex = (int)(x / wavelength);
            var basey = (int)(y / wavelength);

            if (basex == x && basey == y)
            {
                res = 0;
                return;
            }

            //get gradient
            var g00 = GetGradient(basex, basey);
            var g10 = GetGradient(basex + 1, basey);
            var g01 = GetGradient(basex, basey + 1);
            var g11 = GetGradient(basex + 1, basey + 1);

            var pos = new Utility.Vector(0, 0);

            pos.X = (x - basex * wavelength) / wavelength; pos.Y = (y - basey * wavelength) / wavelength;
            var n00 = Influence(g00, pos);

            pos.X = (x - (basex + 1) * wavelength) / wavelength;
            var n10 = Influence(g10, pos);

            pos.X = (x - basex * wavelength) / wavelength; pos.Y = (y - (basey + 1) * wavelength) / wavelength;
            var n01 = Influence(g01, pos);

            pos.X = (x - (basex + 1) * wavelength) / wavelength;
            var n11 = Influence(g11, pos);

            var x_shortage = (x - basex * wavelength) / wavelength;
            var y_shortage = (y - basey * wavelength) / wavelength;
            var nx0        = n00 * (1 - Fade(x_shortage)) + n10 * Fade(x_shortage);
            var nx1        = n01 * (1 - Fade(x_shortage)) + n11 * Fade(x_shortage);

            res = nx0 * (1 - Fade(y_shortage)) + nx1 * Fade(y_shortage);
        }