Walker Variation

I messed around with the Walker example for a few days, but I wasn’t happy with anything I was producing. Then, I got a job and have had very little time since I started. Here is an adaptation of the Walker example from class. I think it sort of behaves like tremors. The square is jumpy, but then it calms down. I have not been able to export the applet yet, but until then here is the code:

Walker w;

void setup() {
size(400,400);
frameRate(30);

// Create a walker object
w = new Walker();

}

void draw() {
background(255);
// Run the walker object
//w.walk();
//w.render();

float rand = random(0, 9);

if (rand < 3) {
w.calmDown();
} else {
w.walk();
}
w.render();
}

class Walker {
float x,y;

Walker() {
x = width/2;
y = height/2;
}

void render() {
stroke(0);
fill(175);
rectMode(CENTER);
rect(x,y,40,40);
}

// Randomly move up, down, left, right, or stay in one place
void walk() {
float vx = random(-8,8);
float vy = random(-8,8);
x += vx;
y += vy;

// Stay on the screen
x = constrain(x,0,width-1);
y = constrain(y,0,height-1);
}

void calmDown() {
float vx = noise(random(-1,1));
float vy = noise(random(-1,1));
x += vx -1;
//x = vx;
y += vy – 1;

// Stay on the screen
x = constrain(x,0,width-1);
y = constrain(y,0,height-1);
}
}

This entry was posted in Etcetera. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>