Truncated at 32000 tokens
View raw output
Here's a complete HTML document with a canvas animation of a pelican pedalling a bicycle across the screen, using requestAnimationFrame to keep the wheels, legs, and looping motion in sync.
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pelican on a Bicycle</title>
<style>
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; background: #bfe7f8; }
canvas { display: block; }
</style>
</head>
<body>
<canvas id="cv"></canvas>
<script>
(function () {
'use strict';
var cv = document.getElementById('cv');
var ctx = cv.getContext('2d');
var W = 0, H = 0, DPR = 1;
var s = 1, localW = 800, groundY = 500;
function resize() {
DPR = Math.min(window.devicePixelRatio || 1, 2);
W = Math.max(1, window.innerWidth);
H = Math.max(1, window.innerHeight);
cv.width = Math.round(W * DPR);
cv.height = Math.round(H * DPR);
cv.style.width = W + 'px';
cv.style.height = H + 'px';
s = Math.min(W / 1150, H / 720);
s = Math.max(0.45, Math.min(1.7, s));
localW = W / s;
groundY = (H * 0.81) / s;
}
window.addEventListener('resize', resize);
resize();
/* ---------------- geometry (bike-local units, ground at y = 0) ---------------- */
var WHEEL_R = 30;
var REAR = { x: -66, y: -30 };
var FRONT = { x: 66, y: -30 };
var BB = { x: -6, y: -48 };
var CRANK_R = 15;
var SEAT = { x: -40, y: -108 };
var HEADT = { x: 44, y: -104 };
var STEM = { x: 48, y: -118 };
var HIP = { x: -38, y: -114 };
var THIGH = 44, SHIN = 46;
var SPEED = 170; // local units per second
var bikeX = -280;
var wheelAngle = 0;
var crankAngle = 0;
var cloudDrift = 0;
var lastT = null;
/* ---------------- helpers ---------------- */
function roundRect(x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function seg(a, b, w, color) {
ctx.beginPath();
ctx.moveTo(a.x, a.y);
ctx.lineTo(b.x, b.y);
ctx.lineWidth = w;
ctx.strokeStyle = color;
ctx.stroke();
}
function pedalPos(a) {
return { x: BB.x + CRANK_R * Math.cos(a), y: BB.y + CRANK_R * Math.sin(a) };
}
/* two-bone IK; knee is chosen to bend forward (+x) */
function solveIK(hip, foot, L1, L2) {
var dx = foot.x - hip.x, dy = foot.y - hip.y;
var d = Math.sqrt(dx * dx + dy * dy);
var maxD = L1 + L2 - 0.01;
if (d > maxD) { var k = maxD / d; dx *= k; dy *= k; d = maxD; }
if (d < 0.001) d = 0.001;
var base = Math.atan2(dy, dx);
var c = (L1 * L1 + d * d - L2 * L2) / (2 * L1 * d);
c = Math.max(-1, Math.min(1, c));
var a = Math.acos(c);
var k1 = { x: hip.x + L1 * Math.cos(base - a), y: hip.y + L1 * Math.sin(base - a) };
var k2 = { x: hip.x + L1 * Math.cos(base + a), y: hip.y + L1 * Math.sin(base + a) };
var knee = (k1.x >= k2.x) ? k1 : k2;
return { knee: knee, foot: { x: hip.x + dx, y: hip.y + dy } };
}
/* ---------------- background ---------------- */
function drawCloud(x, y, sc) {
var span = W + 700;
var cx = ((x + 350) % span + span) % span - 350;
ctx.save();
ctx.translate(cx, y);
ctx.scale(sc, sc);
ctx.fillStyle = 'rgba(255,255,255,0.88)';
ctx.beginPath();
ctx.arc(0, 0, 28, 0, Math.PI * 2);
ctx.arc(30, 7, 21, 0, Math.PI * 2);
ctx.arc(-31, 8, 19, 0, Math.PI * 2);
ctx.arc(7, -15, 20, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
}
function drawSkyAndGround() {
var horizon = H * 0.55;
var roadTop = H * 0.76;
/* sky */
var sg = ctx.createLinearGradient(0, 0, 0, horizon + 60);
sg.addColorStop(0, '#79c6ec');
sg.addColorStop(0.55, '#b9e4f7');
sg.addColorStop(1, '#eaf8fd');
ctx.fillStyle = sg;
ctx.fillRect(0, 0, W, horizon + 60);
/* sun */
var sr = Math.min(W, H) * 0.05;
ctx.beginPath();
ctx.arc(W * 0.82, H * 0.15, sr * 1.8, 0, Math.PI * 2);
ctx.fillStyle = 'rgba(255,241,181,0.28)';
ctx.fill();
ctx.beginPath();
ctx.arc(W * 0.82, H * 0.15, sr, 0, Math.PI * 2);
ctx.fillStyle = 'rgba(255,244,196,1)';
ctx.fill();
/* clouds */
drawCloud(W * 0.14 + cloudDrift, H * 0.17, 1);
drawCloud(W * 0.50 + cloudDrift * 0.72, H * 0.10, 0.75);
drawCloud(W * 0.80 + cloudDrift * 0.5, H * 0.27, 0.58);
/* far hills */
ctx.beginPath();
ctx.moveTo(-60, horizon + 60);
ctx.quadraticCurveTo(W * 0.13, horizon - 74, W * 0.34, horizon + 12);
ctx.quadraticCurveTo(W * 0.55, horizon - 92, W * 0.77, horizon + 8);
ctx.quadraticCurveTo(W * 0.92, horizon - 46, W + 60, horizon + 22);
ctx.lineTo(W + 60, horizon + 120);
ctx.lineTo(-60, horizon + 120);
ctx.closePath();
ctx.fillStyle = '#a9d5a0';
ctx.fill();
/* nearer hills */
ctx.beginPath();
ctx.moveTo(-60, horizon + 70);
ctx.quadraticCurveTo(W * 0.24, horizon + 4, W * 0.48, horizon + 56);
ctx.quadraticCurveTo(W * 0.72, horizon + 6, W + 60, horizon + 48);
ctx.lineTo(W + 60, horizon + 140);
ctx.lineTo(-60, horizon + 140);
ctx.closePath();
ctx.fillStyle = '#8fc97f';
ctx.fill();
/* grass */
var gg = ctx.createLinearGradient(0, horizon + 40, 0, roadTop);
gg.addColorStop(0, '#7fbe6f');
gg.addColorStop(1, '#5f9f56');
ctx.fillStyle = gg;
ctx.fillRect(0, horizon + 40, W, roadTop - horizon - 40 + 2);
/* road */
ctx.fillStyle = '#5a6169';
ctx.fillRect(0, roadTop, W, H - roadTop);
ctx.fillStyle = '#4b5158';
ctx.fillRect(0, roadTop, W, 5);
/* dashed centre line (scrolls with the bike) */
var dashW = 70, period = 140;
var off = ((bikeX * s) % period + period) % period;
ctx.fillStyle = 'rgba(240,230,200,0.85)';
for (var x = -period; x < W + period; x += period) {
ctx.fillRect(x - off, H * 0.905, dashW, 6);
}
}
/*