-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
51 lines (40 loc) · 1.47 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
import {Graph} from "./js/graph.js";
import {Renderer} from "./js/Renderer.js";
import {Earth} from "./js/GameEngine.js";
import {hexToRgb} from "./js/util.js";
const colorInput = document.getElementById("colorInput");
const subdivisionsInput = document.getElementById("subdivisionsInput");
const lightningInput = document.getElementById("lightningInput");
let graph = new Graph(3);
let color = {"r":0.5,"g":0.9,"b":0.8};
graph.setRGBColor(color.r,color.g,color.g);
colorInput.addEventListener("input",event => {
color = hexToRgb(colorInput.value);
graph.setRGBColor(color.r, color.g, color.b);
changeGraph(graph)
});
subdivisionsInput.addEventListener("input", event => {
graph = new Graph(parseInt(subdivisionsInput.value));
graph.setRGBColor(color.r, color.g, color.b);
changeGraph(graph);
})
lightningInput.addEventListener("input", event => {
engine.renderWithLighting = lightningInput.checked
})
const positions = graph.getPositions();
const indices = [...Array(positions.length).keys()];
const colors = graph.getColors();
const normals = graph.getNormals();
const canvasElement = document.getElementById("glcanvas");
const engine = new Renderer({
"canvasElement": canvasElement,
"positions": positions,
"indices": indices,
"colors": colors,
"normals": normals
});
const changeGraph = (newGraph) => {
engine.setColors(newGraph.getColors())
engine.setPositions(newGraph.getPositions())
engine.setNormals(newGraph.getNormals())
}