We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
I've got a similar online example. But it's much worse. They almost always go to top left: :-&
http://Studio.ProcessingTogether.com/sp/pad/export/ro.91FXxn8BG2fPL
yeah.. but why?
Perhaps because if you sample too roughly along the line then your samples will exhibit bias? Your sample steps in walkPerl are 0.01. That might be too rough.
Here is a previous discussion with working examples that might help:
If you are trying to tune a particular random walker to stay in-bounds over long periods, you might need to add a bit to the upper or lower end of your mapped range -- and/or change noiseDetail -- and/or cheat by measuring the long term average bias and periodically nudging it back towards 0.
BTW, your example code gives a step of 10. That doesn't seem right....