Loading...
Logo
Processing Forum

2D-Perlin

in Programming Questions  •  1 year ago  
Hello people,

I'm trying to use noise() to create a colormap but instead of "blobs" of color(/white) i get stripes and i can't really figure out why. As always help will be greatly appreciated.

Thanks,
FRid

Copy code
  1. import processing.opengl.*;

    float inc1 = 0;
    float inc2 = 0;

    float amount1 = random(0.005, 0.01);
    float amount2 = random(0.005, 0.01);

    color c;
    int value1 = 0;
    int value2 = 0;

    void setup() {
      size(800,500,OPENGL);
      frameRate(60);
      background(0);
     
      println(amount1+" "+amount2);
     
    }

    void draw() {
      for (int i=0;i<width;i=i+25) {
        inc1 = (inc1+amount1)00;
       
        for (int j=0;j<width;j=j+25) {
         
          inc2 = (inc2+amount2)00;
          //value1 = int(noise(inc1) * 127);
          //value2 = int(noise(inc2) * 127);
          value2 = int(noise(inc1, inc2) * 255);
          //c = color(value1+value2);
          c = color(value2);
          stroke(0);
          fill(c);
          rect(i,j,25,500);
         
        }   
      }
     
    }

Replies(2)

Re: 2D-Perlin

1 year ago
Two things.

One; you have a two-dimensional for loop but you are only updating inc1 once every row. That's mostly why you are seeing the stripes. You should move that to where inc2 is updating.

Two; your amount1 and amount2 variables are too small. Bump them up and the noise will take larger steps.

I turned the framerate down so you can see each frame a little better.

import processing.opengl.*;

float inc1 = 0;
float inc2 = 0;

float amount1 = random(0.005, 0.5);
float amount2 = random(0.005, 0.5);

color c;
int value1 = 0;
int value2 = 0;

void setup() {
  size(800,500,OPENGL);
  frameRate(1);
  background(0);
  
  println(amount1+" "+amount2);
  
}

void draw() {
  for (int i=0;i<width;i=i+25) {
    
    for (int j=0;j<width;j=j+25) {
      inc1 = (inc1+amount1);
      inc2 = (inc2+amount2);
      //value1 = int(noise(inc1) * 127);
      //value2 = int(noise(inc2) * 127);
      value2 = int(noise(inc1, inc2) * 255);
      //c = color(value1+value2);
      c = color(value2);
      stroke(0);
      fill(c);
      rect(i,j,25,500);
      
    }    
  }
  
}

Re: 2D-Perlin

1 year ago
Oops, didn't see your reply before...

Searching the forum i found a solution which is working for me, thanks for the help though.

FRid

Copy code
  1. import processing.opengl.*;

    float noiseScale= .12;
    color c;
    float sijs = 25;
    float inc = 0.001;

    void setup() {
      size(800,500,OPENGL);
      frameRate(60);
      background(0);
     
     
    }

    void draw() {
      inc = (inc+0.001) % 500;
      //noiseScale = (noiseScale+0.001) % 0.25;
     
      float xoff = 0.0; 
      println(noiseScale);

      for (float i=0;i<width;i=i+sijs) {

        xoff += noiseScale;
        float yoff  = 0.0;
       
        for (float j=0;j<width;j=j+sijs) {
         
          yoff += noiseScale;
          float value = int(noise(xoff+inc, yoff+inc) * 255);
          float sijsMod = int(noise(xoff+inc, yoff+inc) * 20);
          /*
          if (value>127) {
            c = color(255);
          } else {
            c = color(0);
          }
          */
          c = color(value);
          stroke(0);
          fill(c);
          rect(i, j, 5+sijsMod, 5+sijsMod);
         
        }   
      }
     
    }