# Generative Art

## Perlin Noise

* In graphics, Noise is a variation of a measurement created by a random process. Imagine static on a TV. &#x20;
* There's hundreds of algorithms that can be used to generate noise, and all of them serve different purposes.&#x20;
* Perlin Noise specifically tends to create variations that feel believeable and realistic to the human eye. Instead of each input having a random value, each input's value is similar to the values around it, creating natural curves, valleys, and mountains. &#x20;
  * Here's an example of a Perlin Noise distribution, vs a more random noise distribution called Simplex noise:\ <img src="https://2981737117-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpsXSs2PlKMMvugfOqD1D%2Fuploads%2FThoEfAAbGK7TGoJG96b4%2Fnoisecomparison.jpg?alt=media&#x26;token=64fb77ab-dbd0-457e-aeb5-05794ab5fe95" alt="" data-size="original">
* As a result of this smoothness, Perlin noise is often used in video games for random terrain generation, as it can help create breathable worlds. &#x20;
* BTC Substance uses a GLSL Shader implementation of Perlin Noise to alter the **displacement** of each point on the substance, creating aesthetically pleasing waves on the surface.&#x20;

  <figure><img src="https://2981737117-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpsXSs2PlKMMvugfOqD1D%2Fuploads%2FrHQfcApjLQU6vjfAnpRA%2FScreenshot%202024-01-24%20at%209.52.03%E2%80%AFAM.png?alt=media&#x26;token=4e7e50c7-5d90-4d1b-a7e6-2c677f626fbc" alt="" width="188"><figcaption><p>Surface waves from Perlin Noise</p></figcaption></figure>
* Every frame, the noise is re-calculated and moved by a very small amount, in accordance with how much time has passed since the ordinal started rendering (called **uTime**)

## Generative Trait Breakdown

As explained in the [Provable Uniqueness section](https://btc-substance.gitbook.io/btc-substance-academy/satributes-and-ordinals-tech#provable-uniqueness), we extract 10 parameters from each Substance's Inscription ID. Here's a breakdown of how those parameters are used:

#### Displacement Factor

* Perlin Noise determines the **shape and distribution** of the waves, but the **displacement factor** determines the **amplitude** of the entire set of waves (or, the maximum difference between the highest mountain and the deepest valley). &#x20;
* Distortion factor values are similar on all substances, but they vary slightly to ensure randomness.
* ```javascript
  float noise = distortion_factor*pnoise(position+uTime, vec3(1.25));
  ```

#### Stripe Factor

* The **stripe factor** determines how fast the colors will cycle on the substance, and the size of each given color value at a given time. It affects the FragmentShader trigonometric function.&#x20;
* A higher stripe factor means you'll see a higher number of colors at any given time. Here's a comparison between the lowest and highest possible stripe factor:
*

```
<figure><img src="https://2981737117-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpsXSs2PlKMMvugfOqD1D%2Fuploads%2FqL19G0A7YLewWRbS65Ki%2FScreenshot%202024-01-24%20at%2011.03.09%E2%80%AFAM.png?alt=media&#x26;token=db653d33-cfde-49f1-bc90-fd94d70b3016" alt="" width="188"><figcaption></figcaption></figure>
```

```
<figure><img src="https://2981737117-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpsXSs2PlKMMvugfOqD1D%2Fuploads%2FbJ0RibqCZYHjn4axDCDP%2FScreenshot%202024-01-24%20at%2011.03.17%E2%80%AFAM.png?alt=media&#x26;token=f02c1e9a-bb1e-472a-b2be-21f220892b9b" alt="" width="188"><figcaption></figcaption></figure>
```

#### RGB Indexes

* Each Substance has a separate value for Red, Green and Blue, from 0 to 1. A value closer to 1 means that the FragmentShader will more often output a color with a higher value in that color (closer to "Red" for a higher Red Index). It is also used in the Fragment Shader trigonometric function
* Here's an example of how the Red Value is calculated each frame:
* `red_index*(cos(uTime/3.0+pos.x*stripe_factor + (timebounce-0.5)*5.0) * 0.5 + dist/4.0),`
  * The "`timebounce`" here refers to a pendulum value toat constantly cycles between 0 and 1, to give the piece a rythmic feel
  * "`dist`" is the distance each point is from the center of the object, which is affected by nosie and disaplcement.
* Here's some examples of a substance with low Blue Index vs a high Blue Index

<figure><img src="https://2981737117-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpsXSs2PlKMMvugfOqD1D%2Fuploads%2FcLiWHOXTnP1apbsPMAep%2FScreenshot%202024-01-24%20at%2011.09.24%E2%80%AFAM.png?alt=media&#x26;token=8a497a21-23a6-4385-b986-2a58bb675a58" alt="" width="197"><figcaption></figcaption></figure>

<figure><img src="https://2981737117-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpsXSs2PlKMMvugfOqD1D%2Fuploads%2FWlEOnESaDg01SQ4hrELS%2FScreenshot%202024-01-24%20at%2011.09.16%E2%80%AFAM.png?alt=media&#x26;token=2f55cf1f-b544-4cad-95d8-e019f949650f" alt="" width="191"><figcaption></figcaption></figure>

#### Base Geometry

* There are 3 Geometries that constitute the basic shape of BTC Substance. There are chosen at random based, but the Icosahedron is the most common.
  * **Icosahedron**, a 20-sided regular polygon
    \*

    ```
    <figure><img src="https://2981737117-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpsXSs2PlKMMvugfOqD1D%2Fuploads%2FzXxTMe3HtHCY9onLKqED%2FScreenshot%202024-01-24%20at%2011.13.54%E2%80%AFAM.png?alt=media&#x26;token=622b8393-8b8e-420c-8342-9dc6496c87e2" alt="" width="188"><figcaption></figcaption></figure>
    ```
  * **Torus**, a regular 3d ring shape
    \*

    ```
    <figure><img src="https://2981737117-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpsXSs2PlKMMvugfOqD1D%2Fuploads%2Fh2ddgcPjYY3bhBvLEIOq%2FScreenshot%202024-01-24%20at%2011.14.16%E2%80%AFAM.png?alt=media&#x26;token=94033a7a-8cea-4cad-8cca-14dec6833f31" alt="" width="188"><figcaption></figcaption></figure>
    ```
  * **Torus Knot**, a continuous shape that twists and turns around the surface of a torus.
    \*

    ```
    <figure><img src="https://2981737117-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpsXSs2PlKMMvugfOqD1D%2Fuploads%2FhFRsd2HoM0LtEeWQphrx%2FScreenshot%202024-01-24%20at%2011.14.42%E2%80%AFAM.png?alt=media&#x26;token=b05c66f9-f0a5-4d0a-80b4-2b8c3398f65f" alt="" width="188"><figcaption></figcaption></figure>
    ```

#### Rotation

* Both the initial rotation and the rotation rate on the X and Z axes are controlled by generative factors.&#x20;
* This insures that when looking at all the pieces at once, they do not sync up, and all have their own unique movement pattern.&#x20;

#### Background Colors

* The background of each BTC Substance consists of 800 independent particles, which oscillate in size to create a "twinkling" effect. &#x20;
* Their primary color is controlled by a generative factor, which ensures that even if two Substances have similar RGB indexes, they will have unique backgrounds and create their own color palettes.<br>

  ```javascript
  color.setHSL( backgroundColorHue + 0.1 * ( i / amount ), 0.7, 0.5 );
  ```
