Beginner needs a bit of advice (related to perlin noise / randomness)
in
Programming Questions
•
5 months ago
I've been going through the book "The Nature of Code" and implementing some of the exercises involving perlin noise / randomness. I've noticed that almost every time I *think* I have one of the exercises working, they all seem to have slightly skewed results. For instance, when implementing perlin noise to draw an ellipse in a supposedly random manner, the ellipse always ends up eventually heading towards the upper left of the screen (where the expected behavior would be for it to hover closer to center.
Here is some example code, perhaps someone can point out the obvious thing I am overlooking :D
- class Walker {
- float xstep,ystep,x,y,tx,ty;
- Walker() {
- tx = 0;
- ty = 10000;
- x = width/2;
- y = width/2;
- }
- void step() {
- xstep = map(noise(tx),0,1,-1,1);
- ystep = map(noise(ty),0,1,-1,1);
- tx += 0.05;
- ty += 0.05;
- x += xstep;
- y += ystep;
- }
- void display() {
- ellipse(x,y,16,16);
- }
- }
- Walker w;
- void setup() {
- size(800,800);
- w = new Walker();
- }
- void draw() {
- w.step();
- w.display();
- }
1