-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
67 lines (50 loc) · 1.77 KB
/
script.js
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
67
import * as THREE from 'https://unpkg.com/[email protected]/build/three.module.js';
import { OrbitControls } from 'https://unpkg.com/[email protected]/examples/jsm/controls/OrbitControls.js';
let canvas = document.querySelector('#canvas');
canvas.width = innerWidth;
canvas.height = innerHeight;
let renderer = new THREE.WebGLRenderer({canvas});
THREE.Object3D.DefaultUp = new THREE.Vector3(0,0,1);
let scene = new THREE.Scene();
scene.background = new THREE.Color('black');
const camera = new THREE.PerspectiveCamera(
60, // fov
canvas.width/canvas.height, // aspect
0.1, // near
500, // far
);
camera.position.set(160, 0, 70);
camera.lookAt(0, 0, 0);
const color = 'white';
const intensity = 0.5;
let lights = new THREE.PointLight(color, intensity);
lights.position.set(10,0,15);
const controls = new OrbitControls(camera, canvas);
controls.target.set(0, 0, 0);
controls.update();
let planeGeo = new THREE.PlaneGeometry(300, 200, 100, 100);
let planeMat = new THREE.MeshPhongMaterial({emissive: 'brown', wireframe: false});
let mesh = new THREE.Mesh(planeGeo, planeMat);
mesh.rotation.set(0, 0, 0);
scene.add(mesh);
scene.add(camera);
scene.add(lights);
let value, inc = new Array(), xOff = new Array(), j=0;
for (var i = 0; i < planeGeo.vertices.length; i++) {
inc.push(Math.floor(10*Math.random()));
xOff.push(planeGeo.vertices[i].x);
}
function animation() {
planeGeo.verticesNeedUpdate = true;
for (var i = 0; i < planeGeo.vertices.length; i++/*i+=inc[j]*/) {
xOff[i] -= 0.5;
value = Vector2D.map(perlin(xOff[i]/50, planeGeo.vertices[i].y/25), 0, 1, 0, 60);
planeGeo.vertices[i].z = Math.abs(value);
}
renderer.render(scene, camera);
requestAnimationFrame(animation);
}
controls.addEventListener('change', () => {
renderer.render(scene, camera);
});
animation();