# Grain texture in Processing

**URL:** https://discourse.processing.org/t/grain-texture-in-processing/34694
**Category:** Project Guidance
**Created:** [January 17, 2022, 6:50pm UTC](https://discourse.processing.org/t/grain-texture-in-processing/34694 "2022-01-17T18:50:14Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Nik](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@Nik](https://discourse.processing.org/u/Nik)
#### Post date: [January 17, 2022, 6:50pm UTC](https://discourse.processing.org/t/grain-texture-in-processing/34694/1 "2022-01-17T18:50:14Z")

</div>

Hello! Does anyone know how to make such textures in Processing as in the photo. Maybe it’s some kind of GLSL shader?

 ![end](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/cfb5162f77b8cddc74fbcede00651f2798f9d674.jpeg)

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [January 18, 2022, 5:16am UTC](https://discourse.processing.org/t/grain-texture-in-processing/34694/2 "2022-01-18T05:16:28Z")

</div>

Hi

I am not sure that I understand your photos here is sketch close for second photo  
and try to run it with this line  
// pixels[j] = color( R,G,B); once again

```auto
void setup() {
  size(500, 400);
}
void draw() {
  loadPixels();

  for (int i = 0; i < pixels.length; i = i+25) {
    int j = int (random (pixels.length ));

    float R = random(255);
    float G = random (255);
    float B = random (255);
    pixels[j] = color( random(255));

    // pixels[j] = color( R,G,B);
  }

  updatePixels();
}

```

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [January 18, 2022, 6:18am UTC](https://discourse.processing.org/t/grain-texture-in-processing/34694/3 "2022-01-18T06:18:00Z")

</div>

hi

also your second photo [Processing Shader Tool](https://discourse.processing.org/t/processing-shader-tool/5476)

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

see this video

[Processing Shader Tool](https://discourse.processing.org/t/processing-shader-tool/5476)

---

<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: [January 18, 2022, 9:44am UTC](https://discourse.processing.org/t/grain-texture-in-processing/34694/4 "2022-01-18T09:44:16Z")

</div>

You could do that by picking up a random x value following a linear distribution and a random y y value following a uniform distribution.

For each (x,y) pair, you can draw a point (or small circle) the color you want.

Here’s the code:

> **Summary**
>
> ```auto
> void setup() {
> size(1000, 500);
> background(255);
>  
> noStroke();
> fill(206, 164, 245);
>  
> for (int i = 0; i < (width * height) / 2; i++) {
> float x = pickRandom();
> float y = random(500);
> ellipse(x, y, 1, 1);
> }
>  
> saveFrame("Reslut.png");
> }
> 
> float pickRandom() {
> while(true) {
> float qualifier = random(1001);
> float rnd = random(1001);
> if (rnd < qualifier) {
> return qualifier;
> }
> }
> }
> 
> ```

And here’s an example result:

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

EDIT: The cool thing with this “technique” is that you can choose any random distribution that you want. So by tweaking the `pickRandom()` function, you can easily get something like this:

 ![Result](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/621725009762b02178e8fbf9c5d56aab5081376d.png)

---

<div class="post-metadata">

### Author: ![Nik](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@Nik](https://discourse.processing.org/u/Nik)
#### Post date: [January 18, 2022, 4:54pm UTC](https://discourse.processing.org/t/grain-texture-in-processing/34694/5 "2022-01-18T16:54:16Z")

</div>

Thanks jafal ! It’s good version.

---

<div class="post-metadata">

### Author: ![Nik](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@Nik](https://discourse.processing.org/u/Nik)
#### Post date: [January 18, 2022, 4:56pm UTC](https://discourse.processing.org/t/grain-texture-in-processing/34694/6 "2022-01-18T16:56:52Z")

</div>

Thanks jb4x! This is what i need.
