# 2D noise

from Red Blob Games
1 Sep 2013

These are some quick & dirty experiments I did with 2D noise. The main article describes 1D noise but the same principles apply here.

This page is rough, and originally was only for me; I haven’t polished it like most of my articles, but decided to share it anyway.

If you just want map generation with noise and don’t care about Fourier Transforms take a look at my newer article.

## 1  Generating noise#

Background: I wanted to generate maps by mixing together sine waves, using the Inverse Fourier Transform. On the introductory article, I do that step by step, with sample code and diagrams for 1D noise. Here I experiment with 2D noise. For each frequency we need to choose an amplitude. By setting the amplitude to $$0$$ we don’t mix that frequency in at all; by setting it to $$1$$ we mix it with full force.

In 2D there’s an amplitude for every combination of X-frequency and Y-frequency. This is too much to specify by hand. So instead, I have three frequency controls:

1. freq start: the lowest frequency $$f_\text{min}$$
2. freq range: the difference between highest and lowest frequency $$f_\text{max} - f_\text{min}$$
3. exponent: $$e$$ shapes the amplitudes in that frequency range ($$\forall f_\text{min} < f ≤ f_\text{max}$$) to be $$f^e$$

See the introductory article for an exploration of the exponent. The TL;DR is that negative exponents are used to generate height map landscapes and positive exponents are useful for placing map features.

Note that there’s some redundancy here. If you only want low frequencies, you could either do that by limiting the frequency range, or by setting the exponent to be low. Similarly, you can limit to high frequencies in two ways. In the next section it’ll be more free form.

Things to try:

1. Low freq start, high freq range, start exponent around -1 for pink noise. Move the exponent slider to see how the same sine waves mixed together differently produce different outputs.
2. Low freq range, exponent near 0, start raising freq start to see how it increases frequencies. You can see what a narrow band of frequencies can produce.
3. Low freq range, exponent near -1, try different freq ranges to see how adding higher frequencies makes the output “grainier”.

Interpreting the noise as a landscape only works well when using negative exponents. Higher exponents are used for non-landscape uses of noise like textures or object placement.

## 2  Sculpting the frequency spectrum#

As explained on the main page, we’re not limited to using exponents. We can use any mix of frequencies. In this section, we’ll start with exponent-shaped frequencies, but then you can change it to anything you want.

Reset the frequency spectrum to use an exponent, then draw on the chart on the left (log-log scale) to generate 2D noise:

Things to try:

1. Low everywhere except a small spike in the middle. Try spikes on the left or right to see what those frequencies look like.
2. Try two spikes. Notice how high frequency spikes have a stronger effect than low frequency spikes. Why is that? I think it’s because the low frequency spike is spread out over space so it’s harder to see, but I’m not sure. It could be something in my code.
3. Try a spike on the very right side. It doesn’t seem to make a difference. Why? I think it’s related to the Nyquist Limit: the very high frequencies produce features that are too fine to be seen in the 128x128 bitmap.

We’re not even limited to frequencies chosen this way; we can choose frequencies separately in the X and Y dimensions. I won’t demo that though.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8897263,"math_prob":0.9215315,"size":3819,"snap":"2020-45-2020-50","text_gpt3_token_len":863,"char_repetition_ratio":0.14076015,"word_repetition_ratio":0.00608828,"special_character_ratio":0.22728463,"punctuation_ratio":0.10471204,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96915424,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-11-25T03:08:31Z\",\"WARC-Record-ID\":\"<urn:uuid:36291897-0742-4915-a828-ad8fbebbea2b>\",\"Content-Length\":\"25928\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2cc1615f-5223-4e08-a6f8-1679341b89bb>\",\"WARC-Concurrent-To\":\"<urn:uuid:92664420-ce31-4a82-b34d-978c91feda39>\",\"WARC-IP-Address\":\"34.198.241.65\",\"WARC-Target-URI\":\"https://www.redblobgames.com/articles/noise/2d/\",\"WARC-Payload-Digest\":\"sha1:KBXFPKMBHTU5D7BAGQ3ISQ5IULQTPHFG\",\"WARC-Block-Digest\":\"sha1:WR7GNRMJ4BG6Q6Z6BYHJM3AALOCBLZK5\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-50/CC-MAIN-2020-50_segments_1606141180636.17_warc_CC-MAIN-20201125012933-20201125042933-00712.warc.gz\"}"}