# Noisy gradients

**URL:** https://discourse.processing.org/t/noisy-gradients/32217
**Category:** Coding Questions
**Created:** [September 12, 2021, 12:32pm UTC](https://discourse.processing.org/t/noisy-gradients/32217 "2021-09-12T12:32:43Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![dimpapadop](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@dimpapadop](https://discourse.processing.org/u/dimpapadop)
#### Post date: [September 12, 2021, 12:32pm UTC](https://discourse.processing.org/t/noisy-gradients/32217/1 "2021-09-12T12:32:43Z")

</div>

hallo, i am wondering how a noise gradient like this that i found on the web could be created in processing.  
Any ideas?

 ![Capture](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/5e74dbb55bb007b850f8d8e4041c0c88821f291d.png)

my idea approaching (so far) is using perlin noise field and blurring gradually.  
Anyone has a better idea?

for example

```auto
/** modification on :
* marble pattern by perlin noise
*
* @author aa_debdeb
* @date 2016/07/24
*/
float noiseX, noiseY;
float noiseLevelX = 0.001;
float noiseLevelY = 0.001;

void setup(){
  size(600, 600);
  noiseX = random(10000);
  noiseY = random(10000);
  stroke(255);
}

void draw(){
  if (mousePressed) filter(BLUR);
  else {
  background(0);
  for(int x = 0; x < width; x++){
    for(int y = 0; y < height; y++){
      float n = noise(x * noiseLevelX + noiseX, y *noiseLevelX + noiseY, frameCount * 0.001);
      if(int(n * 200) % 2 == 0){
        stroke(255);
        point(x, y);
      }
    }
  }
  }
}

```

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [September 12, 2021, 1:01pm UTC](https://discourse.processing.org/t/noisy-gradients/32217/2 "2021-09-12T13:01:20Z")

</div>

Hello,

Start with a working example or image:

> **[Noise2D / Examples](https://processing.org/examples/noise2d.html)**
>
> Using 2D noise to create simple texture.

Modulate the brightness to give a ripple effect.

If the brightness is 0 to 1:

`modBrightness = 0.5 + 0.5*sin(brightness*1*TAU); //1 cycle`

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/27bf5cd81d2f6bd263a75bdbcdd26f0a7f6200c1.jpeg)

`modBrightness = 0.5 + 0.5*sin(brightness*4*TAU); //4 cycles`

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/bebe442ef4770019aa499a683dd282820207b656.jpeg)

References:

- [https://processing.org/examples/noise2d.html](https://processing.org/examples/noise2d.html)
- [https://processing.org/tutorials/trig](https://processing.org/tutorials/trig)
- [https://processing.org/examples/graphing2dequation.html](https://processing.org/examples/graphing2dequation.html)

I think I helped too much so will leave the rest with you.

8 cycles:

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7eb9eb1b390531e69ef5f3b9c2302e0fb5db716e.jpeg)

`:)`

---

<div class="post-metadata">

### Author: ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)
#### Post date: [September 12, 2021, 1:12pm UTC](https://discourse.processing.org/t/noisy-gradients/32217/3 "2021-09-12T13:12:21Z")

</div>

Hello,

One approach could be as followed.

Start by creating a strip pattern:

```auto
void setup() {
  size(500, 500);
  
  loadPixels();
  for (int i = 0; i < width; i++) {
    for (int j = 0; j < height; j++) {
      pixels[i + j * width] = color(getPatternValue(i, j));
    }
  }
  updatePixels();
}

float getPatternValue(float i, float j) {
  return 255 * (0.5 * cos(0.3 * j) + 0.5);
}

```

![Pattern](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/56fbf3df0a3a1454da53562075c3a2d73a9ee908.png)

From this, you can sample you pattern by rotating the space depending on a 2D noise value. Something like this:

```auto
float noiseScale = 0.004;

void setup() {
  size(500, 500);
  
  loadPixels();
  for (int i = 0; i < width; i++) {
    for (int j = 0; j < height; j++) {
      float angle = TWO_PI * noise(i * noiseScale, j * noiseScale);
      float x = i * cos(angle) - j * sin(angle);
      float y = i * sin(angle) - j * cos(angle);
      pixels[i + j * width] = color(getPatternValue(x, y));
    }
  }
  updatePixels();
}

float getPatternValue(float i, float j) {
  return 255 * (0.5 * cos(0.3 * j) + 0.5);
}

```

![FinalResult](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/bdb1c5cfc5b099b5d5f68433d3857135e5c4318d.jpeg)

---

<div class="post-metadata">

### Author: ![dimpapadop](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@dimpapadop](https://discourse.processing.org/u/dimpapadop)
#### Post date: [September 12, 2021, 1:15pm UTC](https://discourse.processing.org/t/noisy-gradients/32217/4 "2021-09-12T13:15:45Z")

</div>

thank you, nice approach i’ll work it

---

<div class="post-metadata">

### Author: ![dimpapadop](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@dimpapadop](https://discourse.processing.org/u/dimpapadop)
#### Post date: [September 12, 2021, 1:18pm UTC](https://discourse.processing.org/t/noisy-gradients/32217/5 "2021-09-12T13:18:14Z")

</div>

thank you guys beautiful & interesting approaches
