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 {
|
||||
overflow: hidden;
|
||||
background: #000;
|
||||
color: #ff0000;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
canvas {
|
||||
@@ -22,11 +24,34 @@
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
#log {
|
||||
position: fixed;
|
||||
top: 10px;
|
||||
left: 10px;
|
||||
z-index: 100;
|
||||
font-size: 12px;
|
||||
max-width: 90%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="bgCanvas"></canvas>
|
||||
<div id="log"></div>
|
||||
<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 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 {
|
||||
constructor() {
|
||||
this.gridSize = 120;
|
||||
this.gridRange = 30;
|
||||
this.gridRange = 20;
|
||||
this.offsetX = 0;
|
||||
this.offsetZ = 0;
|
||||
this.triangles = [];
|
||||
@@ -154,20 +173,17 @@
|
||||
class Airplane {
|
||||
constructor() {
|
||||
this.vertices = [];
|
||||
this.faces = [];
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
const verts = [];
|
||||
|
||||
const segments = 8;
|
||||
const fuselageLength = 80;
|
||||
const fuselageRadius = 8;
|
||||
const segments = 8;
|
||||
|
||||
for (let i = 0; i < segments; i++) {
|
||||
const angle = (i / segments) * Math.PI * 2;
|
||||
verts.push(new Point3D(
|
||||
this.vertices.push(new Point3D(
|
||||
Math.cos(angle) * fuselageRadius,
|
||||
Math.sin(angle) * fuselageRadius,
|
||||
0
|
||||
@@ -175,45 +191,20 @@
|
||||
}
|
||||
|
||||
for (let i = 0; i < segments; i++) {
|
||||
const angle1 = (i / segments) * Math.PI * 2;
|
||||
const angle2 = ((i + 1) % segments / segments) * Math.PI * 2;
|
||||
verts.push(new Point3D(
|
||||
Math.cos(angle1) * fuselageRadius,
|
||||
Math.sin(angle1) * fuselageRadius,
|
||||
const angle = (i / segments) * Math.PI * 2;
|
||||
this.vertices.push(new Point3D(
|
||||
Math.cos(angle) * fuselageRadius,
|
||||
Math.sin(angle) * fuselageRadius,
|
||||
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 wingChord = 25;
|
||||
const wingY = -2;
|
||||
|
||||
const wingBackLeft = verts.length;
|
||||
verts.push(new Point3D(-wingSpan / 2, wingY, 10));
|
||||
verts.push(new Point3D(-wingSpan / 2 + 5, wingY, 35));
|
||||
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;
|
||||
this.vertices.push(new Point3D(-wingSpan / 2, wingY, 10));
|
||||
this.vertices.push(new Point3D(-wingSpan / 2 + 5, wingY, 35));
|
||||
this.vertices.push(new Point3D(wingSpan / 2 - 5, wingY, 35));
|
||||
this.vertices.push(new Point3D(wingSpan / 2, wingY, 10));
|
||||
}
|
||||
|
||||
update() {
|
||||
@@ -236,23 +227,24 @@
|
||||
ctx.fill();
|
||||
});
|
||||
|
||||
this.vertices.forEach((v, i) => {
|
||||
const nextIdx = (i + 1) % this.vertices.length;
|
||||
if (nextIdx <= 2) return;
|
||||
const p1 = v.project();
|
||||
const p2 = this.vertices[nextIdx].project();
|
||||
for (let i = 0; i < this.vertices.length - 1; i++) {
|
||||
if (i === 7) continue;
|
||||
const p1 = this.vertices[i].project();
|
||||
const p2 = this.vertices[i + 1].project();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(p1.x, p1.y);
|
||||
ctx.lineTo(p2.x, p2.y);
|
||||
ctx.stroke();
|
||||
});
|
||||
}
|
||||
|
||||
ctx.shadowBlur = 0;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const landscape = new Landscape();
|
||||
const airplane = new Airplane();
|
||||
addLog('Objects created');
|
||||
|
||||
function animate() {
|
||||
ctx.fillStyle = '#000';
|
||||
@@ -268,6 +260,10 @@
|
||||
}
|
||||
|
||||
animate();
|
||||
addLog('Animation started');
|
||||
} catch (e) {
|
||||
addLog('CATCH: ' + e.message);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user