Add error display
This commit is contained in:
1 parent
ae50725495
commit
ef80e2a775
1 file changed
+47
-51
+47
-51
@@ -14,6 +14,8 @@
|
|||||||
body {
|
body {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background: #000;
|
background: #000;
|
||||||
|
color: #ff0000;
|
||||||
|
font-family: monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas {
|
canvas {
|
||||||
@@ -22,11 +24,34 @@
|
|||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#log {
|
||||||
|
position: fixed;
|
||||||
|
top: 10px;
|
||||||
|
left: 10px;
|
||||||
|
z-index: 100;
|
||||||
|
font-size: 12px;
|
||||||
|
max-width: 90%;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<canvas id="bgCanvas"></canvas>
|
<canvas id="bgCanvas"></canvas>
|
||||||
|
<div id="log"></div>
|
||||||
<script>
|
<script>
|
||||||
|
const log = document.getElementById('log');
|
||||||
|
function addLog(msg) {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.textContent = msg;
|
||||||
|
log.appendChild(div);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('error', function(e) {
|
||||||
|
addLog('ERROR: ' + e.message + ' at line ' + e.lineno);
|
||||||
|
});
|
||||||
|
|
||||||
|
addLog('Script start');
|
||||||
|
|
||||||
const canvas = document.getElementById('bgCanvas');
|
const canvas = document.getElementById('bgCanvas');
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
@@ -59,16 +84,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function rotateY(p, angle) {
|
|
||||||
const cos = Math.cos(angle);
|
|
||||||
const sin = Math.sin(angle);
|
|
||||||
return { x: p.x * cos - p.z * sin, y: p.y, z: p.x * sin + p.z * cos };
|
|
||||||
}
|
|
||||||
|
|
||||||
class Landscape {
|
class Landscape {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.gridSize = 120;
|
this.gridSize = 120;
|
||||||
this.gridRange = 30;
|
this.gridRange = 20;
|
||||||
this.offsetX = 0;
|
this.offsetX = 0;
|
||||||
this.offsetZ = 0;
|
this.offsetZ = 0;
|
||||||
this.triangles = [];
|
this.triangles = [];
|
||||||
@@ -154,20 +173,17 @@
|
|||||||
class Airplane {
|
class Airplane {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.vertices = [];
|
this.vertices = [];
|
||||||
this.faces = [];
|
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
const verts = [];
|
const segments = 8;
|
||||||
|
|
||||||
const fuselageLength = 80;
|
const fuselageLength = 80;
|
||||||
const fuselageRadius = 8;
|
const fuselageRadius = 8;
|
||||||
const segments = 8;
|
|
||||||
|
|
||||||
for (let i = 0; i < segments; i++) {
|
for (let i = 0; i < segments; i++) {
|
||||||
const angle = (i / segments) * Math.PI * 2;
|
const angle = (i / segments) * Math.PI * 2;
|
||||||
verts.push(new Point3D(
|
this.vertices.push(new Point3D(
|
||||||
Math.cos(angle) * fuselageRadius,
|
Math.cos(angle) * fuselageRadius,
|
||||||
Math.sin(angle) * fuselageRadius,
|
Math.sin(angle) * fuselageRadius,
|
||||||
0
|
0
|
||||||
@@ -175,45 +191,20 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < segments; i++) {
|
for (let i = 0; i < segments; i++) {
|
||||||
const angle1 = (i / segments) * Math.PI * 2;
|
const angle = (i / segments) * Math.PI * 2;
|
||||||
const angle2 = ((i + 1) % segments / segments) * Math.PI * 2;
|
this.vertices.push(new Point3D(
|
||||||
verts.push(new Point3D(
|
Math.cos(angle) * fuselageRadius,
|
||||||
Math.cos(angle1) * fuselageRadius,
|
Math.sin(angle) * fuselageRadius,
|
||||||
Math.sin(angle1) * fuselageRadius,
|
|
||||||
fuselageLength
|
fuselageLength
|
||||||
));
|
));
|
||||||
verts.push(new Point3D(
|
|
||||||
Math.cos(angle2) * fuselageRadius,
|
|
||||||
Math.sin(angle2) * fuselageRadius,
|
|
||||||
fuselageLength
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
const tipIdx = verts.length;
|
|
||||||
verts.push(new Point3D(0, 0, fuselageLength + 30));
|
|
||||||
|
|
||||||
for (let i = 0; i < segments; i++) {
|
|
||||||
const next = (i + 1) % segments;
|
|
||||||
const middleStart = segments + i * 2;
|
|
||||||
const middleNext = segments + ((i + 1) % segments) * 2;
|
|
||||||
|
|
||||||
verts.push([baseIdx = i, next].forEach(() => {}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const wingSpan = 100;
|
const wingSpan = 100;
|
||||||
const wingChord = 25;
|
|
||||||
const wingY = -2;
|
const wingY = -2;
|
||||||
|
this.vertices.push(new Point3D(-wingSpan / 2, wingY, 10));
|
||||||
const wingBackLeft = verts.length;
|
this.vertices.push(new Point3D(-wingSpan / 2 + 5, wingY, 35));
|
||||||
verts.push(new Point3D(-wingSpan / 2, wingY, 10));
|
this.vertices.push(new Point3D(wingSpan / 2 - 5, wingY, 35));
|
||||||
verts.push(new Point3D(-wingSpan / 2 + 5, wingY, 35));
|
this.vertices.push(new Point3D(wingSpan / 2, wingY, 10));
|
||||||
verts.push(new Point3D(wingSpan / 2 - 5, wingY, 35));
|
|
||||||
verts.push(new Point3D(wingSpan / 2, wingY, 10));
|
|
||||||
|
|
||||||
this.faces.push([wingBackLeft, wingBackLeft + 1, wingBackLeft + 2]);
|
|
||||||
this.faces.push([wingBackLeft, wingBackLeft + 2, wingBackLeft + 3]);
|
|
||||||
|
|
||||||
this.vertices = verts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
@@ -236,23 +227,24 @@
|
|||||||
ctx.fill();
|
ctx.fill();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.vertices.forEach((v, i) => {
|
for (let i = 0; i < this.vertices.length - 1; i++) {
|
||||||
const nextIdx = (i + 1) % this.vertices.length;
|
if (i === 7) continue;
|
||||||
if (nextIdx <= 2) return;
|
const p1 = this.vertices[i].project();
|
||||||
const p1 = v.project();
|
const p2 = this.vertices[i + 1].project();
|
||||||
const p2 = this.vertices[nextIdx].project();
|
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(p1.x, p1.y);
|
ctx.moveTo(p1.x, p1.y);
|
||||||
ctx.lineTo(p2.x, p2.y);
|
ctx.lineTo(p2.x, p2.y);
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
});
|
}
|
||||||
|
|
||||||
ctx.shadowBlur = 0;
|
ctx.shadowBlur = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const landscape = new Landscape();
|
const landscape = new Landscape();
|
||||||
const airplane = new Airplane();
|
const airplane = new Airplane();
|
||||||
|
addLog('Objects created');
|
||||||
|
|
||||||
function animate() {
|
function animate() {
|
||||||
ctx.fillStyle = '#000';
|
ctx.fillStyle = '#000';
|
||||||
@@ -268,6 +260,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
animate();
|
animate();
|
||||||
|
addLog('Animation started');
|
||||||
|
} catch (e) {
|
||||||
|
addLog('CATCH: ' + e.message);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in new issue
Block a user