-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
71 lines (59 loc) · 2.45 KB
/
index.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
67
68
69
70
71
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>SVG Voxel Engine</title>
</head>
<body>
<script type="module">
import svgVoxelEngineFactory from './svgVoxelEngineFactory.js';
import { hueShift } from './svgVoxelEngineFactory.js';
const size = 32;
const groundOffset = 5;
let numberOfTreeMax = 200;
const treeLeafColor = "#21c766";
const treeLeafHueShift = -140;
const svgVoxelEngine = svgVoxelEngineFactory({ size });
const R = () => {
svgVoxelEngine.clear();
// Add basic ground
svgVoxelEngine.addFullSlab(1, "#21C786");
svgVoxelEngine.addFullSlab(2, "#94979A", 5);
const treeFactory = position => {
const { x, y } = position;
const z = (x > groundOffset && x < size - groundOffset + 1 && y > groundOffset && y < size - groundOffset + 1) ? 3 : 2;
const treeType = Math.ceil(Math.random() * 3)
switch (treeType) {
case 1: {
// basic
svgVoxelEngine.addBox({ x, y, z }, "#AC7D4D", { xSize: 1, ySize: 1, zSize: 1 });
svgVoxelEngine.addBox({ x: x - 1, y: y - 1, z: z + 2 }, hueShift(treeLeafColor, Math.random() * treeLeafHueShift), { xSize: 3, ySize: 3, zSize: 3 - Math.floor(Math.random() * 2) });
break;
}
case 2: {
// S
svgVoxelEngine.addBox({ x, y, z }, "#AC7D4D", { xSize: 1, ySize: 1, zSize: 1 });
svgVoxelEngine.addBox({ x, y: y - 1, z: z + 2 }, hueShift(treeLeafColor, Math.random() * treeLeafHueShift), { xSize: 2, ySize: 2, zSize: 6 - Math.floor(Math.random() * 5) })
break;
}
case 3: {
// XS
svgVoxelEngine.addBox({ x, y, z }, "#AC7D4D", { xSize: 1, ySize: 1, zSize: 2 });
svgVoxelEngine.addBox({ x, y, z: z + 1 }, hueShift(treeLeafColor, Math.random() * treeLeafHueShift), { xSize: 1, ySize: 1, zSize: 8 - Math.floor(Math.random() * 8) })
break;
}
}
}
const numberOfTree = Math.floor(Math.random() * numberOfTreeMax + 1);
for (let i = 0; i < numberOfTree; i++) {
treeFactory({ x: Math.ceil(Math.random() * (size - 2)) + 1, y: Math.ceil(Math.random() * (size - 2)) + 1 })
}
svgVoxelEngine.render();
}
R();
document.addEventListener('click', R)
</script>
</body>
</html>