Datasets:
File size: 20,093 Bytes
01f0f49 | 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pirate Deck Cannon</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #0d1114;
}
#app {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 24px;
left: 26px;
z-index: 2;
max-width: min(390px, calc(100vw - 52px));
padding: 16px 18px;
color: #f4e7c9;
background: linear-gradient(145deg, rgba(24, 20, 15, 0.88), rgba(20, 17, 13, 0.72));
border: 1px solid rgba(225, 184, 111, 0.35);
border-radius: 14px;
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(12px);
pointer-events: none;
}
.title-card h1 {
margin: 0 0 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(22px, 3vw, 32px);
font-weight: 600;
letter-spacing: 0.025em;
}
.title-card p {
margin: 0;
color: #bda887;
font-size: 13px;
line-height: 1.45;
}
.controls-hint {
position: fixed;
right: 22px;
bottom: 20px;
z-index: 2;
padding: 9px 12px;
color: #c4b291;
background: rgba(12, 15, 17, 0.68);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 999px;
font-size: 12px;
letter-spacing: 0.02em;
pointer-events: none;
backdrop-filter: blur(8px);
}
@media (max-width: 600px) {
.title-card {
top: 14px;
left: 14px;
padding: 12px 14px;
}
.title-card p {
display: none;
}
.controls-hint {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="title-card">
<h1>Pirate Deck Cannon</h1>
<p>A turntable-ready cannon mounted on a wooden carriage, with a stacked load of cannonballs.</p>
</div>
<div class="controls-hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.getElementById("app");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101518);
scene.fog = new THREE.Fog(0x101518, 17, 42);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive 3D pirate deck cannon");
app.appendChild(renderer.domElement);
// Lighting
scene.add(new THREE.HemisphereLight(0xb8c9d3, 0x3a2618, 1.65));
const keyLight = new THREE.DirectionalLight(0xffe0ad, 3.2);
keyLight.position.set(5.5, 9, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x769ab4, 1.35);
rimLight.position.set(-6, 5, -5);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xd78b42, 22, 12, 2);
warmFill.position.set(2.5, 3.5, 3.5);
scene.add(warmFill);
// Deterministic procedural wood texture.
function createWoodTexture() {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 512;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#704327";
ctx.fillRect(0, 0, 512, 512);
let seed = 9137;
const random = () => {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
};
for (let y = -10; y < 530; y += 3) {
const amplitude = 2 + random() * 8;
const frequency = 0.012 + random() * 0.028;
const phase = random() * Math.PI * 2;
ctx.beginPath();
for (let x = 0; x <= 520; x += 8) {
const waveY =
y +
Math.sin(x * frequency + phase) * amplitude +
Math.sin(x * frequency * 0.43 + phase) * amplitude * 0.35;
if (x === 0) ctx.moveTo(x, waveY);
else ctx.lineTo(x, waveY);
}
ctx.strokeStyle = `rgba(35, 15, 7, ${0.08 + random() * 0.16})`;
ctx.lineWidth = 0.5 + random() * 2.2;
ctx.stroke();
}
for (let i = 0; i < 18; i++) {
const x = random() * 512;
const y = random() * 512;
const rx = 8 + random() * 25;
const ry = 2 + random() * 7;
ctx.beginPath();
ctx.ellipse(x, y, rx, ry, 0, 0, Math.PI * 2);
ctx.strokeStyle = "rgba(35, 15, 7, 0.16)";
ctx.lineWidth = 1.2;
ctx.stroke();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(2, 2);
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const woodTexture = createWoodTexture();
const materials = {
wood: new THREE.MeshStandardMaterial({
map: woodTexture,
color: 0xffffff,
roughness: 0.82,
metalness: 0.02
}),
darkWood: new THREE.MeshStandardMaterial({
map: woodTexture,
color: 0x8b5938,
roughness: 0.9,
metalness: 0.01
}),
iron: new THREE.MeshStandardMaterial({
color: 0x252b2d,
roughness: 0.48,
metalness: 0.78
}),
blackIron: new THREE.MeshStandardMaterial({
color: 0x101517,
roughness: 0.58,
metalness: 0.72
}),
steel: new THREE.MeshStandardMaterial({
color: 0x8b9291,
roughness: 0.35,
metalness: 0.9
}),
brass: new THREE.MeshStandardMaterial({
color: 0xb68a45,
roughness: 0.38,
metalness: 0.8
}),
ball: new THREE.MeshStandardMaterial({
color: 0x8d918e,
roughness: 0.42,
metalness: 0.82
}),
ballSeam: new THREE.MeshStandardMaterial({
color: 0x484d4c,
roughness: 0.55,
metalness: 0.68
}),
ground: new THREE.MeshStandardMaterial({
color: 0x252c2d,
roughness: 0.96,
metalness: 0.02
})
};
const model = new THREE.Group();
model.name = "Pirate deck cannon assembly";
scene.add(model);
const turntable = new THREE.Group();
turntable.name = "Rotating turntable";
model.add(turntable);
function addMesh(
geometry,
material,
parent,
position = [0, 0, 0],
rotation = [0, 0, 0],
name = "Unnamed mesh"
) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.rotation.set(...rotation);
mesh.name = name;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Turntable
addMesh(
new THREE.CylinderGeometry(2.08, 2.32, 0.24, 64),
materials.darkWood,
turntable,
[0, 0.12, 0],
[0, 0, 0],
"Turntable pedestal"
);
addMesh(
new THREE.CylinderGeometry(2.28, 2.28, 0.16, 64),
materials.wood,
turntable,
[0, 0.32, 0],
[0, 0, 0],
"Turntable deck"
);
addMesh(
new THREE.TorusGeometry(2.19, 0.035, 10, 80),
materials.brass,
turntable,
[0, 0.415, 0],
[Math.PI / 2, 0, 0],
"Turntable brass rim"
);
// Wooden carriage
const carriage = new THREE.Group();
carriage.name = "Wooden carriage";
model.add(carriage);
addMesh(
new THREE.BoxGeometry(4.8, 0.28, 3.2),
materials.wood,
carriage,
[0, 0.6, 0],
[0, 0, 0],
"Carriage deck"
);
addMesh(
new THREE.BoxGeometry(4.95, 0.13, 3.34),
materials.darkWood,
carriage,
[0, 0.78, 0],
[0, 0, 0],
"Carriage top rail"
);
for (const z of [-1.48, 1.48]) {
addMesh(
new THREE.BoxGeometry(4.85, 0.24, 0.18),
materials.darkWood,
carriage,
[0, 0.84, z],
[0, 0, 0],
"Carriage side rail"
);
}
for (const x of [-1.72, 1.72]) {
addMesh(
new THREE.BoxGeometry(0.22, 0.25, 2.85),
materials.darkWood,
carriage,
[x, 0.79, 0],
[0, 0, 0],
"Carriage cross brace"
);
}
for (const x of [-2.02, 2.02]) {
addMesh(
new THREE.BoxGeometry(0.2, 0.22, 2.9),
materials.darkWood,
carriage,
[x, 0.78, 0],
[0, 0, 0],
"Carriage end brace"
);
}
// Deck bolts
for (const x of [-1.9, -0.95, 0.1, 1.15, 2.1]) {
for (const z of [-1.48, 1.48]) {
addMesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.035, 12),
materials.brass,
carriage,
[x, 0.865, z],
[0, 0, 0],
"Carriage bolt"
);
}
}
// Four wooden carriage wheels
function createWheel(x, z, facing) {
const wheel = new THREE.Group();
wheel.name = "Carriage wheel";
wheel.position.set(x, 0.57, z);
carriage.add(wheel);
addMesh(
new THREE.CylinderGeometry(0.55, 0.55, 0.34, 32),
materials.darkWood,
wheel,
[0, 0, 0],
[Math.PI / 2, 0, 0],
"Wheel rim"
);
addMesh(
new THREE.TorusGeometry(0.45, 0.075, 8, 36),
materials.wood,
wheel,
[0, 0, 0],
[0, 0, 0],
"Wheel outer rim"
);
addMesh(
new THREE.CylinderGeometry(0.19, 0.19, 0.4, 20),
materials.iron,
wheel,
[0, 0, 0],
[Math.PI / 2, 0, 0],
"Wheel hub"
);
const spokeZ = facing * 0.18;
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
addMesh(
new THREE.BoxGeometry(1.02, 0.09, 0.065),
materials.wood,
wheel,
[Math.cos(angle) * 0.39, Math.sin(angle) * 0.39, spokeZ],
[0, 0, angle],
"Carriage wheel spoke"
);
}
}
createWheel(-1.72, -1.38, -1);
createWheel(1.72, -1.38, -1);
createWheel(-1.72, 1.38, 1);
createWheel(1.72, 1.38, 1);
// Deck cannon
const cannon = new THREE.Group();
cannon.name = "Iron deck cannon";
model.add(cannon);
// Barrel support cheeks
for (const z of [-0.5, 0.5]) {
addMesh(
new THREE.BoxGeometry(0.52, 0.34, 0.25),
materials.iron,
cannon,
[-0.18, 1.19, z],
[0, 0, 0],
"Cannon cheek block"
);
}
// Trunnion
addMesh(
new THREE.CylinderGeometry(0.28, 0.33, 0.55, 24),
materials.iron,
cannon,
[-0.62, 1.34, 0],
[0, 0, Math.PI / 2],
"Cannon trunnion"
);
// Main barrel, tapering toward the muzzle
addMesh(
new THREE.CylinderGeometry(0.19, 0.34, 2.65, 28),
materials.iron,
cannon,
[0.85, 1.31, 0],
[0, 0, -Math.PI / 2],
"Cannon barrel"
);
// Barrel bands
addMesh(
new THREE.TorusGeometry(0.345, 0.045, 8, 36),
materials.iron,
cannon,
[-0.49, 1.31, 0],
[0, Math.PI / 2, 0],
"Rear barrel band"
);
addMesh(
new THREE.TorusGeometry(0.315, 0.04, 8, 36),
materials.iron,
cannon,
[0.12, 1.31, 0],
[0, Math.PI / 2, 0],
"Middle barrel band"
);
addMesh(
new THREE.TorusGeometry(0.225, 0.045, 8, 36),
materials.iron,
cannon,
[2.19, 1.31, 0],
[0, Math.PI / 2, 0],
"Muzzle barrel band"
);
// Dark bore and muzzle lip
addMesh(
new THREE.CylinderGeometry(0.13, 0.16, 0.2, 24),
materials.blackIron,
cannon,
[2.28, 1.31, 0],
[0, 0, -Math.PI / 2],
"Cannon bore"
);
addMesh(
new THREE.TorusGeometry(0.19, 0.025, 8, 32),
materials.steel,
cannon,
[2.31, 1.31, 0],
[0, Math.PI / 2, 0],
"Muzzle lip"
);
// Rear collar and sight
addMesh(
new THREE.CylinderGeometry(0.37, 0.37, 0.18, 24),
materials.iron,
cannon,
[-0.72, 1.34, 0],
[0, 0, Math.PI / 2],
"Cannon rear collar"
);
addMesh(
new THREE.BoxGeometry(0.18, 0.13, 0.12),
materials.brass,
cannon,
[-0.56, 1.58, 0.5],
[0, 0, 0],
"Front sight"
);
addMesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.3, 12),
materials.brass,
cannon,
[-0.56, 1.49, 0.5],
[0, 0, 0],
"Sight post"
);
// Handle behind the cannon
for (const z of [-0.28, 0.28]) {
addMesh(
new THREE.CylinderGeometry(0.045, 0.045, 0.48, 12),
materials.iron,
cannon,
[-0.92, 1.31, z],
[0, 0, Math.PI / 2],
"Handle post"
);
}
addMesh(
new THREE.BoxGeometry(0.18, 0.12, 0.72),
materials.iron,
cannon,
[-0.92, 1.56, 0],
[0, 0, 0],
"Cannon handle"
);
// Cannonball stack
const ballStack = new THREE.Group();
ballStack.name = "Stack of cannonballs";
model.add(ballStack);
const ballPositions = [
[-2.02, 1.76, 0.95],
[-1.52, 1.76, 0.95],
[-1.02, 1.76, 0.95],
[-1.77, 2.54, 0.95],
[-1.27, 2.54, 0.95],
[-1.52, 3.32, 0.95]
];
for (const [x, y, z] of ballPositions) {
const radius = 0.38;
addMesh(
new THREE.SphereGeometry(radius, 32, 24),
materials.ball,
ballStack,
[x, y, z],
[0, 0, 0],
"Cannonball"
);
// Equatorial seam
addMesh(
new THREE.TorusGeometry(radius + 0.006, 0.014, 6, 36),
materials.ballSeam,
ballStack,
[x, y, z],
[Math.PI / 2, 0, 0],
"Cannonball equatorial seam"
);
// Vertical seam
addMesh(
new THREE.TorusGeometry(radius + 0.006, 0.012, 6, 36),
materials.ballSeam,
ballStack,
[x, y, z],
[0, 0, 0],
"Cannonball vertical seam"
);
}
// Small brass carriage plaque
const plaque = new THREE.Group();
plaque.name = "Carriage plaque";
plaque.position.set(0, 0.87, 1.675);
carriage.add(plaque);
addMesh(
new THREE.BoxGeometry(1.45, 0.28, 0.035),
materials.brass,
plaque,
[0, 0, 0],
[0, 0, 0],
"Carriage plaque"
);
addMesh(
new THREE.BoxGeometry(0.34, 0.035, 0.012),
materials.iron,
plaque,
[-0.38, 0, 0.025],
[0, 0, 0],
"Plaque inset"
);
// Plain ground plane
const ground = addMesh(
new THREE.PlaneGeometry(100, 100),
materials.ground,
scene,
[0, 0, 0],
[-Math.PI / 2, 0, 0],
"Plain ground plane"
);
ground.castShadow = false;
// Custom orbit controls implemented without external addons.
const cameraTarget = new THREE.Vector3(0, 1.35, 0);
const desired = {
theta: 0.72,
phi: 1.08,
radius: 10.6
};
const current = {
theta: desired.theta,
phi: desired.phi,
radius: desired.radius
};
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
current.theta += (desired.theta - current.theta) * 0.08;
current.phi += (desired.phi - current.phi) * 0.08;
current.radius += (desired.radius - current.radius) * 0.08;
const sinPhi = Math.sin(current.phi);
camera.position.set(
cameraTarget.x + current.radius * sinPhi * Math.sin(current.theta),
cameraTarget.y + current.radius * Math.cos(current.phi),
cameraTarget.z + current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
desired.theta = 0.72;
desired.phi = 1.08;
desired.radius = 10.6;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desired.theta -= deltaX * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - deltaY * 0.005,
0.34,
1.48
);
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
5.5,
18
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") desired.theta += 0.12;
if (event.key === "ArrowRight") desired.theta -= 0.12;
if (event.key === "ArrowUp") desired.phi = Math.max(0.34, desired.phi - 0.08);
if (event.key === "ArrowDown") desired.phi = Math.min(1.48, desired.phi + 0.08);
if (event.key === "+" || event.key === "=") desired.radius = Math.max(5.5, desired.radius - 0.5);
if (event.key === "-") desired.radius = Math.min(18, desired.radius + 0.5);
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const turntableSpeed = reducedMotion ? 0.035 : 0.22;
const initialTurn = reducedMotion ? 0 : -0.28;
let elapsed = 0;
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
turntable.rotation.y = initialTurn + elapsed * turntableSpeed;
updateCamera();
renderer.render(scene, camera);
}
updateCamera();
animate();
</script>
</body>
</html>
|