Documentation000_upload
Transform your PDFs into Flipbooks and boost your revenue!
Leverage SEO-optimized Flipbooks, powerful backlinks, and multimedia content to professionally showcase your products and significantly increase your reach.
// Claus Rytter Bruun de Neergaard
// www.clausclaus.com, March, 2013
// Tested in Processing 2.0b8
// RANDOM WALK, THREE-DIMENSIONAL WORLD, FULLY GROWN, TIME-BASED REGEN
import peasy.*;
// declare object instances
PeasyCam cam;
Wander w;
// global variables
int n = 3000;
int step = 5;
float angle = 0.5;
int savedTime;
int totalTime = 1500;
int space = 500;
int subdiv = 10;
// declare array to contain PVector
PVector[] pos = new PVector[n];
void setup() {
size(670, 250, P3D);
background(245);
savedTime = millis();
cam = new PeasyCam(this, 400);
w = new Wander();
w.calc();
}
void draw() {
background(245);
// rotate camera to begin with
rotateX(-0.5);
rotateY(angle);
angle += 0.01;
// recalculate every five (5) secs
int passedTime = millis() - savedTime;
if (passedTime > totalTime) {
w.calc();
savedTime = millis();
}
// number of points
// random movement step size
// beginning rotation
// time vars to regulate recalc
// time vars to regulate recalc
// size of box(es)
// size of sub-box(es)
for (int i = 0; i < n; i++) {
// point
float d = dist(0, 0, 0, pos[i].x, pos[i].y, pos[i].z);
float dmap = map(d, 0, 1000, 2, 45);
strokeWeight(dmap);
stroke(50, dmap*2);
point(pos[i].x, pos[i].y, pos[i].z);
}
}
// class Wander
class Wander {
int x, y, z;
Wander() {
for (int i = 0; i < n; i++) {
pos[i] = new PVector(0, 0, 0);
}
}
void calc() {
// reset coordinates
x = 0;
y = 0;
z = 0;
for (int i = 0; i < n; i++) {
// create random integer for direction
int r = int(random(0, 25));
// compare random integer to direction numbers,
// and add position value
if (r == 0) {
x -= step;
y += step;
z += step;
}
else if (r == 1) {
y += step;
z += step;
}
else if (r == 2) {
x += step;
y += step;
z += step;
}
else if (r == 3) {
x += step;
z += step;
}
else if (r == 4) {
x += step;
y -= step;
z += step;
}
else if (r == 5) {
y -= step;
z += step;
}
else if (r == 6) {
x -= step;
y -= step;
z += step;
}
else if (r == 7) {
x -= step;
z += step;
}
else if (r == 8) {
z += step;
}
else if (r == 9) {
x -= step;
y += step;
}
else if (r == 10) {
y += step;
}
else if (r == 11) {
x += step;
y += step;
}
else if (r == 12) {
x += step;
}
else if (r == 13) {
x += step;
y -= step;
}
else if (r == 14) {
y -= step;
}
else if (r == 15) {
x -= step;
y -= step;
}
else if (r == 16) {
x -= step;
}
else if (r == 17) {
x -= step;
y += step;
z -= step;
}
else if (r == 18) {
y += step;
z -= step;
}
else if (r == 19) {
x += step;
y += step;
z -= step;
}
else if (r == 20) {
x += step;
z -= step;
}
else if (r == 21) {
x += step;
y -= step;
z -= step;
}
else if (r == 22) {
y -= step;
z -= step;
}
else if (r == 23) {
x -= step;
y -= step;
z -= step;
}
else if (r == 24) {
x -= step;
z -= step;
}
else if (r == 25) {
z -= step;
}
// write position values to array
pos[i].set(x, y, z);
}
}
}
code studies --- 5 | 29