Perlin Noise random walker driving to top left?

Hi all.. I attempted to make a perlin noise based random walker (after watching Daniel Schiffmans Youtube videos). However, my walker always seems to end up at the top right of the screen. Why is this? I googled for this same problem and found that it can happen because of casting between int and floats in processing.. however, I'm only using floats throughout my sketch. Thanks. :)

Here's my sketch

ArrayList<Walker> walkers;

int NUMWALKERS = 10;
Walker a;
import processing.pdf.*;
float steps = 0;
boolean record = false;

void setup(){
  a = new Walker();
  size(500,500);
  background(255);
  textSize(32);
  beginRecord(PDF, "PerlinNoiseWalker-####.pdf");

}

void draw(){
  fill(255);
  noStroke();
  fill(0, 102, 153, 60);
    a.walkPerl();
    a.render();
}

void mousePressed(){
  record = true;
  endRecord();
  println("Saving PDF");
}

And the walker class }`

class Walker{
  private float x = width/2;
  private float y = height/2;
  public static final float step = 10.0;

  float t = 0;
  float t2 = 0;

  public Walker(){
    //give each walker a random 'seed' for the perlin noise;
    t = 0.01;
    t2 = t+10;
  }

  public void walkPerl(){
    t += 0.01;
    t2 += 0.01;
    float xN = noise(t);
    xN = map(xN,0,1,-step,+step);
    x += xN;
    x = constrain(x,0,width);

    float yN = noise(t2);
    yN = map(yN,0,1,-step,+step);
    y += yN;
    y = constrain(y,0,height);
  }

  public void render(){
    //stroke(#9E07E0);
    //point(x,y);
    ellipse(x,y,5,5);
  }
}

The effect is somewhat subtle but it's there:

Answers

Sign In or Register to comment.