예제 #1
0
        public Color[][] FillCircle(int width, double offsetX, double offsetY, PerlinOptions options)
        {
            float red = options.RandomColor.Next(options.MinRed, options.MaxRed) / options.FactorRed;
            float green = options.RandomColor.Next(options.MinGreen, options.MaxGreen) / options.FactorGreen;
            float blue = options.RandomColor.Next(options.MinBlue, options.MaxBlue) / options.FactorBlue;

            var data = PrepareColorArray(width, width);

            int r = width / 2; // radius
            int ox = r, oy = r; // origin

            for (int x = -r; x < r; x++)
            {
                int height = (int)Math.Sqrt(r * r - x * x);

                for (int y = -height; y < height; y++)
                {
                    float noise = (float)Noise.RidgedMF(
                        offsetX + (x + ox) * options.PerlinNoiseStep, offsetY + (y + oy) * options.PerlinNoiseStep,
                        0, options.Octaves, options.Lacunarity, options.Gain, options.Offset);
                    data[x + ox][y + oy] = ModifyColor(noise, options, red, green, blue);
                }
            }
            return data;
        }
예제 #2
0
        public Color[][] FillCircle(int width, double offsetX, double offsetY, PerlinOptions options)
        {
            float red   = options.RandomColor.Next(options.MinRed, options.MaxRed) / options.FactorRed;
            float green = options.RandomColor.Next(options.MinGreen, options.MaxGreen) / options.FactorGreen;
            float blue  = options.RandomColor.Next(options.MinBlue, options.MaxBlue) / options.FactorBlue;

            var data = PrepareColorArray(width, width);

            int r = width / 2;  // radius
            int ox = r, oy = r; // origin

            for (int x = -r; x < r; x++)
            {
                int height = (int)Math.Sqrt(r * r - x * x);

                for (int y = -height; y < height; y++)
                {
                    float noise = (float)Noise.RidgedMF(
                        offsetX + (x + ox) * options.PerlinNoiseStep, offsetY + (y + oy) * options.PerlinNoiseStep,
                        0, options.Octaves, options.Lacunarity, options.Gain, options.Offset);
                    data[x + ox][y + oy] = ModifyColor(noise, options, red, green, blue);
                }
            }
            return(data);
        }
예제 #3
0
        public void RenderCircle(RoBitmap bitmap, PerlinOptions options, int radius)
        {
            var data = PerlinTexture.FillCircle(radius, OffsetX, OffsetY, options);

            for (int x = 0; x < data.Length; x++)
            {
                for (int y = 0; y < data[x].Length; y++)
                {
                    bitmap.SetPixel(x, y, data[x][y]);
                }
            }

            OffsetX += step * radius;
            OffsetY += step * radius;
        }
예제 #4
0
        public void RenderSquare(RoBitmap bitmap, PerlinOptions options, int w, int h)
        {
            var data = PerlinTexture.FillRectangle(w, h, OffsetX, OffsetY, options);

            for (int x = 0; x < data.Length; x++)
            {
                for (int y = 0; y < data[x].Length; y++)
                {
                    bitmap.SetPixel(x, y, data[x][y]);
                }
            }

            OffsetX += step * w;
            OffsetY += step * h;
        }
예제 #5
0
        public Color ModifyColor(float noise, PerlinOptions options, float red, float green, float blue)
        {
            int colorRed   = 0;
            int colorGreen = 0;
            int colorBlue  = 0;

            colorRed = ColorFloatToInt(noise * red);
            if (options.UseCosineOnRed)
            {
                colorRed = ColorFloatToInt((float)Math.Cos(red / noise));
            }

            colorGreen = ColorFloatToInt(noise * green);
            if (options.UseCosineOnGreen)
            {
                colorGreen = ColorFloatToInt((float)Math.Cos(green / noise));
            }

            colorBlue = ColorFloatToInt(noise * blue);
            if (options.UseCosineOnBlue)
            {
                colorBlue = ColorFloatToInt((float)Math.Cos(blue / noise));
            }

            if (options.ReverseRed)
            {
                colorRed = 255 - colorRed;
            }

            if (options.ReverseGreen)
            {
                colorGreen = 255 - colorGreen;
            }

            if (options.ReverseBlue)
            {
                colorBlue = 255 - colorBlue;
            }

            return(Color.FromArgb(255, colorRed, colorGreen, colorBlue));
        }
예제 #6
0
        public Color[][] FillRectangle(int width, int height, double offsetX, double offsetY, PerlinOptions options)
        {
            float red = options.RandomColor.Next(options.MinRed, options.MaxRed) / options.FactorRed;
            float green = options.RandomColor.Next(options.MinGreen, options.MaxGreen) / options.FactorGreen;
            float blue = options.RandomColor.Next(options.MinBlue, options.MaxBlue) / options.FactorBlue;

            Color[][] data = PrepareColorArray(width, height);
            double x = 0;
            double y = 0;
            double offX = x;

            for (int v = 0; v < width; v++)
            {
                y += options.PerlinNoiseStep;
                x = offX;

                for (int u = 0; u < height; u++)
                {
                    float noise = (float)Noise.RidgedMF(offsetX + x, offsetY + y, 0, options.Octaves, options.Lacunarity, options.Gain, options.Offset);
                    data[v][u] = ModifyColor(noise, options, red, green, blue);

                    x += options.PerlinNoiseStep;
                }
            }

            return data;
        }
예제 #7
0
        public Color ModifyColor(float noise, PerlinOptions options, float red, float green, float blue)
        {
            int colorRed = 0;
            int colorGreen = 0;
            int colorBlue = 0;

            colorRed = ColorFloatToInt(noise * red);
            if (options.UseCosineOnRed)
            {
                colorRed = ColorFloatToInt((float)Math.Cos(red / noise));
            }

            colorGreen = ColorFloatToInt(noise * green);
            if (options.UseCosineOnGreen)
            {
                colorGreen = ColorFloatToInt((float)Math.Cos(green / noise));
            }

            colorBlue = ColorFloatToInt(noise * blue);
            if (options.UseCosineOnBlue)
            {
                colorBlue = ColorFloatToInt((float)Math.Cos(blue / noise));
            }

            if (options.ReverseRed)
                colorRed = 255 - colorRed;

            if (options.ReverseGreen)
                colorGreen = 255 - colorGreen;

            if (options.ReverseBlue)
                colorBlue = 255 - colorBlue;

            return Color.FromArgb(255, colorRed, colorGreen, colorBlue);
        }
예제 #8
0
        public Color[][] FillRectangle(int width, int height, double offsetX, double offsetY, PerlinOptions options)
        {
            float red   = options.RandomColor.Next(options.MinRed, options.MaxRed) / options.FactorRed;
            float green = options.RandomColor.Next(options.MinGreen, options.MaxGreen) / options.FactorGreen;
            float blue  = options.RandomColor.Next(options.MinBlue, options.MaxBlue) / options.FactorBlue;

            Color[][] data = PrepareColorArray(width, height);
            double    x    = 0;
            double    y    = 0;
            double    offX = x;


            for (int v = 0; v < width; v++)
            {
                y += options.PerlinNoiseStep;
                x  = offX;

                for (int u = 0; u < height; u++)
                {
                    float noise = (float)Noise.RidgedMF(offsetX + x, offsetY + y, 0, options.Octaves, options.Lacunarity, options.Gain, options.Offset);
                    data[v][u] = ModifyColor(noise, options, red, green, blue);

                    x += options.PerlinNoiseStep;
                }
            }

            return(data);
        }