I have some weird problems. I would need some help.
import peasy.*;
int resolution = 100;
float r = 500;
float lat,lon;
float xoff,yoff;
PVector[][] globularLandscape;
float rangeMin = 0;
float rangeMax = 40;
PeasyCam cam;
void setup() {
size(400,400, P3D);
cam = new PeasyCam(this, 1000);
globularLandscape = new PVector[resolution+1][resolution+1];
noStroke();
frameRate(30);
//fill(50);
}
void draw() {
background(0);
for (int i = 0; i < resolution+1; i++) {
lat = map(i, 0, resolution, 0, PI);
xoff = 0;
for (int j = 0; j < resolution+1; j++) {
lon = map(j, 0, resolution, 0, TWO_PI);
float x = r * sin(lat) * cos(lon) + map(noise(xoff, yoff),0 ,1, rangeMin, rangeMax);
float y = r * sin(lat) * sin(lon) + map(noise(xoff, yoff),0 ,1, rangeMin, rangeMax);
float z = r * cos(lat) + map(noise(xoff, yoff),0 ,1, rangeMin, rangeMax);
//float x = r * sin(lat) * cos(lon) + random(-10,100);
//float y = r * sin(lat) * sin(lon) + random(-10,100);
//float z = r * cos(lat) + random(-10,100);
globularLandscape[i][j] = new PVector(x, y, z);
xoff += 0.05;
//PVector v = PVector.random3D();
//v.mult(7.7);
//globularLandscape[i][j].add(v);
}
yoff += 0.05;
}
for (int i = 0; i < resolution; i++) {
beginShape(TRIANGLE_STRIP);
for (int j = 0; j < resolution+1; j++) {
PVector v1 = globularLandscape[i][j];
PVector v2 = globularLandscape[i+1][j];
float x = (v1.x + v2.x) / 2;
float y = (v1.y + v2.y) / 2;
float z = (v1.z + v2.z) / 2;
float def = sqrt(x * x + y * y + z * z);
if(def > r) {
fill(255, 255, 255);
} else if (def < r) {
fill(183, 109, 31);
} else {
fill(62, 201, 24);
}
vertex(v1.x, v1.y, v1.z);
//println(def);
vertex(v2.x, v2.y, v2.z);
}
endShape();
}
}
‘def’ is the value which holds the distance of the vertex. Basicaly I would like to make mountains with snow on it ,but the results can be seen on the picture. Can somebody help me or explain what`s going on ?
P.S. Sorry for bad language.