Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am making a perlin noise generator on a WFP and i have generated the noise map but would im not sure how to apply smoothing to said map, here is what i have so far


What I have tried:

private void btnGenerate_Click(object sender, EventArgs e)
       {
           CellHeight = 8;
           CellWidth = 8;
           MapWidth = 80;
           MapHeight = 80;
           double[,] noise_map = new double[MapWidth, MapHeight];
           TranslateNoise(InitWhiteNoise(noise_map));
       }

       private void TranslateNoise(double[,] noise_map)
       {
           Bitmap noiseMap = new Bitmap(MapWidth * CellWidth, MapHeight * CellHeight);
           using (Graphics pMap = Graphics.FromImage(noiseMap))
           {
               <pre>                pMap.Clear(Color.Black);
               for (int y = 0; y < MapHeight; y++)
               {
                   for (int x = 0; x < MapWidth; x++)
                   {
                       pMap.FillRectangle(
                           noise_map[x, y] == 0 ? Brushes.White :
                           noise_map[x, y] == 1 ? Brushes.WhiteSmoke :
                           noise_map[x, y] == 2 ? Brushes.Gainsboro :
                           noise_map[x, y] == 3 ? Brushes.LightGray :
                           noise_map[x, y] == 4 ? Brushes.Silver :
                           noise_map[x, y] == 5 ? Brushes.Gray :
                           noise_map[x, y] == 6 ? Brushes.DarkGray :
                           noise_map[x, y] == 7 ? Brushes.LightSlateGray :
                           noise_map[x, y] == 8 ? Brushes.SlateGray :
                           noise_map[x, y] == 9 ? Brushes.DimGray : Brushes.Black, x * CellWidth, y * CellHeight,
                           CellWidth, CellHeight);
                   }
               }
           }

           pbMap.Image = noiseMap;
       }
       private double[,] InitWhiteNoise(double[,] noise_map)
       {
           Random noise = new Random();
           for (int x = 0; x < MapWidth; x++)
               for (int y = 0; y < MapHeight; y++)
                   noise_map[x, y] = noise.Nex(0, 11);

           return noise_map;
       }
Posted
Updated 3-Apr-21 4:33am
v3
Comments
[no name] 2-Apr-21 1:23am    
Lots of noise in FillRectangle.
Dave Kreskowiak 2-Apr-21 2:05am    
You can start by breaking out the FillRectangle call into individual statements. The code you have now is nowhere near production ready. It's unsupportable and will only make the next person to see that code and modify it wish death upon you.
ThePersonWhoCodes 3-Apr-21 7:21am    
code has been updated

1 solution

You don't have a method of "smoothing" either the noise map or the graphic representation.

What you did was essentially pick 11 colors, then go through all the pixels in the image and assign each pixel one of those colors. There's no possible interpolation between your points.

One method to fix this is to map your 80x80 noise map to a much larger bitmap so you can interpolate values between points in your map. You cannot use named color values either. You'd have to be able to pick percentages of white (255,255,255) based on the value between two points in your map and the distance in pixels between those mapped points in your image.

The other method is to use a function to limit the possible values in your noise map. As you move across the map, the function will dictate the upper or lower limits of the values that can be picked at any position in the map.

See Noise Functions and Map Generation[^] for a good, and interactive, explanation of this.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900