-
Notifications
You must be signed in to change notification settings - Fork 0
/
3d-terrain-generator.html
66 lines (59 loc) · 2.04 KB
/
3d-terrain-generator.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/p5.js"></script>
<script>
//this is fork1
new p5();
let cls, rws;
let sc = 10;
let width = window.innerWidth;
let height = window.innerHeight;
let terrain = [];
let flying = 0;
let terrainR = -100;
function setup () {
cls = width*2 / sc;
rws = height*2 / sc;
for(let x = 0; x < cls; x++) {
terrain[x] = [];
for(let y = 0; y < rws - 1; y++) {
terrain[x][y] = 0; //specify default value for now.
}
}
angleMode(DEGREES);
createCanvas(width,height,WEBGL);
noFill();
strokeWeight(0.25)
stroke(250,50);
fill(0,150);
// fill(255);
}
function draw () {
terrainR += 1;
flying -= 0.51;
var yoff = flying;
for (var y = 0; y < rws; y++) {
var xoff = 0;
for (var x = 0; x < cls; x++) {
terrain[x][y] = map(noise(xoff, yoff), 0, 1, -100, 100);
xoff += 0.2;
}
yoff += 0.2;
}
background(50,100,200);
// translate(width/2,height/2);
rotateX(80);
translate(-width,-height);
for(let y = 0; y < rws; y++) {
beginShape(TRIANGLE_STRIP);
for(let x = 0; x < cls; x++) {
// camera(0.0)
// vertex(x*sc, y*sc,terrain[x][y]);
// vertex(x*sc, (y+1)*sc, terrain[x][y+1]);
vertex(x*sc, y*sc, terrain[x][y]);
vertex(x*sc, (y+1)*sc, terrain[x][y+1]);
}
endShape();
}
}
</script>
</html>