Up and Down arrow keys to speed up and slow down. Left and Right arrow keys to move.
xxxxxxxxxx
int cols, rows, w=4000, h=2200, s=20;
float fy=0, yrt=-.1, fx=0;
float[][] z;
boolean tilt=false, untilt=false, acc=false, unacc=false;
int xdir, ydir;
float xrate=.5, xamount=0, yrate=.5, yamount=0;
void settings() {
size(1920, 1080, P3D);
}
void setup() {
size(1920, 1080, P3D);
background(0);
cols=w/s;
rows=h/s;
z=new float[cols][rows];
}
void draw() {
background(0);
noFill();
fy+=(yrt+map(yamount, -15, 15, -.5, -.225)+.275);
fx+=map(xamount, -15, 15, .1, -.1);
float yoff=fy;
for (int y=0; y<rows; y++) {
float xoff=fx;
for (int x=0; x<cols; x++) {
z[x][y]=map(noise(xoff, yoff), 0, 1, -100, 100);
xoff+=.15;
}
yoff+=.15;
}
if (tilt) {
Tilt();
}
if (untilt) {
Untilt();
}
if (acc) {
Acc();
}
if (unacc) {
Unacc();
}
translate(width/2, height/2);
rotateX((PI/3)+(radians(yamount/2)));
rotateY(radians(xamount));
translate(-w/2, (-h/2)-400);
for (int y=0; y<rows-1; y++) {
beginShape(TRIANGLE_STRIP);
for (int x=0; x<cols; x++) {
stroke(map(z[x][y], -100, 100, 0, 255));
//fill(map(z[x][y],-100,100,0,255));
vertex(x*s, y*s, z[x][y]);
vertex(x*s, (y+1)*s, z[x][y+1]);
}
endShape();
}
}
void Tilt() {
xamount=constrain(xamount+(xrate*xdir), -15, 15);
}
void Untilt() {
if (xamount==0) {
untilt=false;
}
xamount=constrain(xamount-(xrate*(xdir)), -15, 15);
}
//-.3,-.05
void Acc() {
//yamount=constrain(yamount+(yrate*ydir),-15,15);
yamount=constrain(yamount+(yrate*ydir), -15, 15);
}
void Unacc() {
if (yamount==0) {
unacc=false;
}
//yamount=constrain(yamount-(yrate*ydir),-15,15);
yamount=constrain(yamount-(yrate*ydir), -15, 15);
}
void keyPressed() {
if (keyCode==LEFT) {
untilt=false;
tilt=true;
xdir=1;
}
if (keyCode==RIGHT) {
untilt=false;
tilt=true;
xdir=-1;
}
if (keyCode==UP) {
unacc=false;
acc=true;
ydir=-1;
}
if (keyCode==DOWN) {
unacc=false;
acc=true;
ydir=1;
}
}
void keyReleased() {
if (keyCode==LEFT || keyCode==RIGHT) {
tilt=false;
untilt=true;
}
if (keyCode==UP || keyCode==DOWN) {
acc=false;
unacc=true;
}
}