Canvas-Video-Html5-2D / Duck-Riding-a-Bicycle.html
mondk's picture
rename
736e6be verified
Raw History Blame Contribute Delete
18.6 kB
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Duck Riding a Bicycle</title>
<style>
html,body{margin:0;padding:0;overflow:hidden;background:#000;}
canvas{display:block;}
</style>
</head>
<body>
<canvas id="c"></canvas>
<script>
const cv = document.getElementById('c');
const ctx = cv.getContext('2d');
const TAU = Math.PI * 2;
// ---- Loop constants ----
const T = 8; // loop length (seconds)
const R = 70; // wheel radius
const WHEEL_TURNS = 12; // wheel turns per loop
const CRANK_TURNS = 6; // pedal turns per loop
const D = TAU * R * WHEEL_TURNS; // ground distance travelled per loop
let W, H, dpr, s, VW, VH, groundY;
function resize(){
dpr = Math.min(window.devicePixelRatio || 1, 2);
W = window.innerWidth; H = 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(H / 900, W / 900);
VW = W / s; VH = H / s;
groundY = VH - 190;
}
window.addEventListener('resize', resize);
resize();
// ---- Seeded random ----
function mulberry(a){return function(){a|=0;a=a+0x6D2B79F5|0;let t=Math.imul(a^a>>>15,1|a);t=t+Math.imul(t^t>>>7,61|t)^t;return((t^t>>>14)>>>0)/4294967296;}}
// ---- Layer helper: seamless tiling ----
function tiles(f, n, p, fn){
const P = f * D / n;
const off = (f * D * p) % P;
for (let x = -off - P; x < VW + P; x += P) fn(x, P);
}
// ---- Pre-generated layer content ----
const rnd = mulberry(12345);
const clouds = [];
for (let i = 0; i < 3; i++) clouds.push({fx: i/3 + rnd()*0.2, y: 60 + rnd()*150, sc: 0.7 + rnd()*0.7});
const trees = [];
for (let i = 0; i < 9; i++) trees.push({fx: i/9 + rnd()*0.07, type: rnd() < 0.45 ? 'pine' : (rnd() < 0.6 ? 'round' : 'bush'), sc: 0.7 + rnd()*0.6, hue: rnd()});
const pebbles = [];
for (let i = 0; i < 10; i++) pebbles.push({fx: rnd(), dy: -18 + rnd()*48, r: 1.5 + rnd()*3});
const meadow = [];
for (let i = 0; i < 16; i++) meadow.push({fx: rnd(), dy: 50 + rnd()*120, type: rnd() < 0.35 ? 'flower' : 'tuft', c: Math.floor(rnd()*4), sc: 0.7 + rnd()*0.6});
const fore = [];
for (let i = 0; i < 6; i++) fore.push({fx: rnd(), sc: 0.8 + rnd()*0.8});
// ---- Background drawing ----
function drawSky(p){
const g = ctx.createLinearGradient(0, 0, 0, groundY);
g.addColorStop(0, '#6ec3f2');
g.addColorStop(0.7, '#bfe6f7');
g.addColorStop(1, '#fdeccc');
ctx.fillStyle = g;
ctx.fillRect(0, 0, VW, VH);
// Sun with rotating rays (12-fold symmetry => seamless)
const sx = VW * 0.8, sy = 130;
ctx.save();
ctx.translate(sx, sy);
ctx.rotate(p * TAU / 12);
ctx.fillStyle = 'rgba(255,230,120,0.35)';
for (let i = 0; i < 12; i++){
ctx.rotate(TAU / 12);
ctx.beginPath();
ctx.moveTo(-8, 55); ctx.lineTo(0, 95); ctx.lineTo(8, 55);
ctx.fill();
}
ctx.restore();
const sg = ctx.createRadialGradient(sx, sy, 10, sx, sy, 55);
sg.addColorStop(0, '#fff7c2'); sg.addColorStop(1, '#ffd23f');
ctx.fillStyle = sg;
ctx.beginPath(); ctx.arc(sx, sy, 48, 0, TAU); ctx.fill();
}
function cloud(x, y, sc){
ctx.save(); ctx.translate(x, y); ctx.scale(sc, sc);
ctx.fillStyle = 'rgba(255,255,255,0.92)';
ctx.beginPath();
ctx.arc(0, 0, 30, 0, TAU);
ctx.arc(35, -15, 38, 0, TAU);
ctx.arc(75, 0, 30, 0, TAU);
ctx.arc(40, 12, 30, 0, TAU);
ctx.fill();
ctx.restore();
}
function drawClouds(p){
tiles(0.18, 1, p, (x, P) => {
for (const c of clouds) cloud(x + c.fx * P, c.y, c.sc);
});
}
function drawMountains(p){
const f = 0.25, P = f * D;
const off = f * D * p;
const base = groundY - 200;
const g = ctx.createLinearGradient(0, base - 160, 0, groundY);
g.addColorStop(0, '#8fa8c8'); g.addColorStop(1, '#c9d6e6');
ctx.fillStyle = g;
ctx.beginPath();
ctx.moveTo(0, groundY);
for (let x = 0; x <= VW + 10; x += 8){
const u = (x + off) / P * TAU;
const y = base - (55*Math.sin(u*2+1) + 35*Math.sin(u*5+2) + 18*Math.sin(u*11+0.5) + 60);
ctx.lineTo(x, y);
}
ctx.lineTo(VW + 10, groundY);
ctx.closePath(); ctx.fill();
}
function drawHills(p){
const f = 0.5, P = f * D;
const off = f * D * p;
const base = groundY - 80;
const g = ctx.createLinearGradient(0, base - 80, 0, groundY);
g.addColorStop(0, '#8fcf6a'); g.addColorStop(1, '#6db552');
ctx.fillStyle = g;
ctx.beginPath();
ctx.moveTo(0, groundY);
for (let x = 0; x <= VW + 10; x += 8){
const u = (x + off) / P * TAU;
const y = base - (30*Math.sin(u*3+0.3) + 18*Math.sin(u*7+1.7) + 30);
ctx.lineTo(x, y);
}
ctx.lineTo(VW + 10, groundY);
ctx.closePath(); ctx.fill();
}
function drawTree(x, y, t){
ctx.save(); ctx.translate(x, y); ctx.scale(t.sc, t.sc);
if (t.type === 'pine'){
ctx.fillStyle = '#7a5230'; ctx.fillRect(-5, -20, 10, 20);
ctx.fillStyle = t.hue < 0.5 ? '#2f7d46' : '#3a8c4f';
for (let i = 0; i < 3; i++){
ctx.beginPath();
ctx.moveTo(-34 + i*7, -18 - i*26);
ctx.lineTo(0, -70 - i*26);
ctx.lineTo(34 - i*7, -18 - i*26);
ctx.closePath(); ctx.fill();
}
} else if (t.type === 'round'){
ctx.fillStyle = '#7a5230'; ctx.fillRect(-6, -40, 12, 40);
ctx.fillStyle = t.hue < 0.5 ? '#4f9e3c' : '#5aab45';
ctx.beginPath();
ctx.arc(0, -70, 36, 0, TAU); ctx.arc(-24, -52, 24, 0, TAU); ctx.arc(24, -52, 24, 0, TAU);
ctx.fill();
ctx.fillStyle = 'rgba(255,255,255,0.12)';
ctx.beginPath(); ctx.arc(-10, -82, 16, 0, TAU); ctx.fill();
} else {
ctx.fillStyle = '#4c9a3a';
ctx.beginPath();
ctx.arc(-18, -12, 18, 0, TAU); ctx.arc(0, -20, 22, 0, TAU); ctx.arc(20, -12, 17, 0, TAU);
ctx.fill();
}
ctx.restore();
}
function drawTrees(p){
const y = groundY - 32;
tiles(0.75, 2, p, (x, P) => {
for (const t of trees) drawTree(x + t.fx * P, y, t);
});
}
function drawGround(p){
// meadow behind road
ctx.fillStyle = '#62ad4b';
ctx.fillRect(0, groundY - 34, VW, 30);
// road
ctx.fillStyle = '#dcc596';
ctx.fillRect(0, groundY - 22, VW, 60);
ctx.fillStyle = '#c7ae7c';
ctx.fillRect(0, groundY - 22, VW, 5);
ctx.fillRect(0, groundY + 33, VW, 5);
// pebbles (move with ground)
tiles(1, 12, p, (x, P) => {
ctx.fillStyle = '#b39a6b';
for (const pb of pebbles){
ctx.beginPath();
ctx.ellipse(x + pb.fx * P, groundY + pb.dy, pb.r * 1.5, pb.r, 0, 0, TAU);
ctx.fill();
}
});
// front meadow
const g = ctx.createLinearGradient(0, groundY + 38, 0, VH);
g.addColorStop(0, '#5aa844'); g.addColorStop(1, '#3f8a33');
ctx.fillStyle = g;
ctx.fillRect(0, groundY + 38, VW, VH - groundY);
const fc = ['#ff6b8a', '#ffffff', '#ffd23f', '#b98cff'];
tiles(1, 6, p, (x, P) => {
for (const m of meadow){
const mx = x + m.fx * P, my = groundY + m.dy;
if (m.type === 'tuft'){
ctx.strokeStyle = '#2f7a2a'; ctx.lineWidth = 2.5; ctx.lineCap = 'round';
ctx.beginPath();
for (let k = -2; k <= 2; k++){
ctx.moveTo(mx + k*3, my);
ctx.quadraticCurveTo(mx + k*5, my - 10*m.sc, mx + k*7, my - 16*m.sc);
}
ctx.stroke();
} else {
ctx.strokeStyle = '#2f7a2a'; ctx.lineWidth = 2;
ctx.beginPath(); ctx.moveTo(mx, my); ctx.lineTo(mx, my - 14*m.sc); ctx.stroke();
ctx.fillStyle = fc[m.c];
for (let k = 0; k < 5; k++){
const a = k * TAU / 5;
ctx.beginPath(); ctx.arc(mx + Math.cos(a)*4*m.sc, my - 14*m.sc + Math.sin(a)*4*m.sc, 3*m.sc, 0, TAU); ctx.fill();
}
ctx.fillStyle = '#ffb000';
ctx.beginPath(); ctx.arc(mx, my - 14*m.sc, 2.4*m.sc, 0, TAU); ctx.fill();
}
}
});
}
function drawForeground(p){
tiles(1.4, 4, p, (x, P) => {
for (const f of fore){
const fx = x + f.fx * P, fy = VH + 5;
ctx.fillStyle = '#2e6e27';
ctx.beginPath();
ctx.moveTo(fx - 30*f.sc, fy);
for (let k = 0; k < 7; k++){
const bx = fx - 30*f.sc + k * 10*f.sc;
ctx.quadraticCurveTo(bx + 2, fy - 40*f.sc, bx + 5*f.sc + (k%2?6:-4), fy - (45 + (k%3)*12)*f.sc);
ctx.quadraticCurveTo(bx + 8*f.sc, fy - 20*f.sc, bx + 10*f.sc, fy);
}
ctx.closePath(); ctx.fill();
}
});
}
// ---- Bicycle + Duck ----
const RH = {x:-110, y:0}, FH = {x:110, y:0}, BB = {x:-10, y:12};
const ST = {x:-38, y:-78}, SADDLE = {x:-44, y:-90};
const HT = {x:82, y:-92}, HB = {x:92, y:-58};
const STEM = {x:76, y:-112}, GRIP = {x:98, y:-118};
const CRANK = 28;
function line(a, b){ ctx.beginPath(); ctx.moveTo(a.x, a.y); ctx.lineTo(b.x, b.y); ctx.stroke(); }
function drawWheel(c, rot){
ctx.save(); ctx.translate(c.x, c.y);
ctx.strokeStyle = '#2b2b2b'; ctx.lineWidth = 9;
ctx.beginPath(); ctx.arc(0, 0, R - 4, 0, TAU); ctx.stroke();
ctx.strokeStyle = '#9aa3ad'; ctx.lineWidth = 3;
ctx.beginPath(); ctx.arc(0, 0, R - 10, 0, TAU); ctx.stroke();
ctx.rotate(rot);
ctx.strokeStyle = '#c3cad2'; ctx.lineWidth = 1.4;
for (let i = 0; i < 16; i++){
const a = i * TAU / 16;
ctx.beginPath(); ctx.moveTo(Math.cos(a)*5, Math.sin(a)*5);
ctx.lineTo(Math.cos(a + 0.2)*(R - 11), Math.sin(a + 0.2)*(R - 11)); ctx.stroke();
}
// valve / reflector marker to show rotation
ctx.fillStyle = '#ff8c00';
ctx.fillRect(R - 30, -3, 12, 6);
ctx.fillStyle = '#555';
ctx.beginPath(); ctx.arc(0, 0, 7, 0, TAU); ctx.fill();
ctx.fillStyle = '#bbb';
ctx.beginPath(); ctx.arc(0, 0, 3, 0, TAU); ctx.fill();
ctx.restore();
}
function legIK(hip, foot, L1, L2){
const dx = foot.x - hip.x, dy = foot.y - hip.y;
let d = Math.hypot(dx, dy);
d = Math.min(d, L1 + L2 - 0.5);
const a = Math.atan2(dy, dx);
const off = Math.acos(Math.max(-1, Math.min(1, (L1*L1 + d*d - L2*L2) / (2*L1*d))));
return {x: hip.x + Math.cos(a - off)*L1, y: hip.y + Math.sin(a - off)*L1};
}
function drawLeg(hip, pedal, color, dark){
const ankle = {x: pedal.x - 2, y: pedal.y - 6};
const knee = legIK(hip, ankle, 68, 68);
ctx.strokeStyle = color; ctx.lineWidth = 7; ctx.lineCap = 'round'; ctx.lineJoin = 'round';
ctx.beginPath(); ctx.moveTo(hip.x, hip.y); ctx.lineTo(knee.x, knee.y); ctx.lineTo(ankle.x, ankle.y); ctx.stroke();
// webbed foot
ctx.fillStyle = color; ctx.strokeStyle = dark; ctx.lineWidth = 1.5;
ctx.beginPath();
ctx.moveTo(ankle.x - 5, ankle.y);
ctx.lineTo(pedal.x + 20, pedal.y - 5);
ctx.quadraticCurveTo(pedal.x + 18, pedal.y - 1, pedal.x + 20, pedal.y + 1);
ctx.lineTo(pedal.x - 8, pedal.y - 1);
ctx.closePath(); ctx.fill(); ctx.stroke();
}
function drawPedalArm(theta, color){
const px = BB.x + Math.cos(theta)*CRANK, py = BB.y + Math.sin(theta)*CRANK;
ctx.strokeStyle = color; ctx.lineWidth = 6; ctx.lineCap = 'round';
ctx.beginPath(); ctx.moveTo(BB.x, BB.y); ctx.lineTo(px, py); ctx.stroke();
ctx.fillStyle = '#333';
ctx.fillRect(px - 9, py - 3, 18, 6);
return {x: px, y: py};
}
function drawWing(from, to, fill, stroke){
const dx = to.x - from.x, dy = to.y - from.y;
const L = Math.hypot(dx, dy), a = Math.atan2(dy, dx);
ctx.save(); ctx.translate(from.x, from.y); ctx.rotate(a);
ctx.fillStyle = fill; ctx.strokeStyle = stroke; ctx.lineWidth = 2; ctx.lineJoin = 'round';
ctx.beginPath();
ctx.moveTo(-6, -16);
ctx.quadraticCurveTo(L*0.55, -20, L + 4, -6);
ctx.lineTo(L + 10, -2); ctx.lineTo(L + 2, 2);
ctx.lineTo(L + 8, 6); ctx.lineTo(L - 4, 8);
ctx.lineTo(L - 2, 12); ctx.lineTo(L - 14, 11);
ctx.quadraticCurveTo(L*0.45, 20, -6, 16);
ctx.closePath(); ctx.fill(); ctx.stroke();
ctx.strokeStyle = 'rgba(150,100,0,0.35)'; ctx.lineWidth = 1.5;
ctx.beginPath(); ctx.moveTo(L*0.35, -6); ctx.quadraticCurveTo(L*0.6, -2, L*0.85, 2); ctx.stroke();
ctx.restore();
}
function drawScene(p){
const theta = p * TAU * CRANK_TURNS;
const wheelRot = p * TAU * WHEEL_TURNS;
const bob = 2.5 * Math.sin(2*theta);
const vib = 0.6 * Math.sin(p * TAU * 24);
const bx = VW * 0.48, by = groundY - R + 2 + vib;
// shadow
ctx.fillStyle = 'rgba(60,40,10,0.22)';
ctx.beginPath(); ctx.ellipse(bx, groundY + 4, 200, 12, 0, 0, TAU); ctx.fill();
ctx.save();
ctx.translate(bx, by);
// wheels
drawWheel(RH, wheelRot);
drawWheel(FH, wheelRot);
const hip = {x: -20, y: -96 + bob};
const hipFar = {x: -26, y: -98 + bob};
// far side crank & leg
const farPedal = drawPedalArm(theta + Math.PI, '#555');
drawLeg(hipFar, farPedal, '#d9741c', '#a8540f');
// far wing
drawWing({x: 4, y: -142 + bob}, {x: GRIP.x - 6, y: GRIP.y - 3}, '#e0a400', '#b07d00');
// frame
ctx.lineCap = 'round'; ctx.lineJoin = 'round';
ctx.strokeStyle = '#e8465c'; ctx.lineWidth = 8;
line(RH, BB); line(RH, ST); line(BB, ST); line(ST, HT); line(BB, HB);
ctx.lineWidth = 10; line(HT, HB);
ctx.lineWidth = 7; line(HB, FH);
// seat post + saddle
ctx.strokeStyle = '#888'; ctx.lineWidth = 5; line(ST, SADDLE);
ctx.fillStyle = '#3a2a22';
ctx.beginPath();
ctx.moveTo(SADDLE.x - 22, SADDLE.y - 4);
ctx.quadraticCurveTo(SADDLE.x, SADDLE.y - 10, SADDLE.x + 22, SADDLE.y - 3);
ctx.quadraticCurveTo(SADDLE.x + 4, SADDLE.y + 6, SADDLE.x - 22, SADDLE.y + 3);
ctx.closePath(); ctx.fill();
// stem & handlebar
ctx.strokeStyle = '#888'; ctx.lineWidth = 5;
line(HT, STEM);
ctx.beginPath(); ctx.moveTo(STEM.x, STEM.y);
ctx.quadraticCurveTo(STEM.x + 18, STEM.y - 10, GRIP.x, GRIP.y); ctx.stroke();
ctx.strokeStyle = '#222'; ctx.lineWidth = 7;
ctx.beginPath(); ctx.moveTo(GRIP.x - 6, GRIP.y + 1); ctx.lineTo(GRIP.x + 6, GRIP.y - 1); ctx.stroke();
// headlight
ctx.fillStyle = '#ffe680';
ctx.beginPath(); ctx.arc(HT.x + 10, HT.y + 6, 5, 0, TAU); ctx.fill();
// fender rear
ctx.strokeStyle = '#e8465c'; ctx.lineWidth = 4;
ctx.beginPath(); ctx.arc(RH.x, RH.y, R + 4, Math.PI*1.05, Math.PI*1.6); ctx.stroke();
// chainring, chain
ctx.strokeStyle = '#444'; ctx.lineWidth = 2;
ctx.beginPath(); ctx.moveTo(BB.x, BB.y - 20); ctx.lineTo(RH.x, RH.y - 9); ctx.stroke();
ctx.beginPath(); ctx.moveTo(BB.x, BB.y + 20); ctx.lineTo(RH.x, RH.y + 9); ctx.stroke();
ctx.fillStyle = '#777';
ctx.beginPath(); ctx.arc(RH.x, RH.y, 9, 0, TAU); ctx.fill();
ctx.save(); ctx.translate(BB.x, BB.y); ctx.rotate(theta);
ctx.fillStyle = '#9a9a9a';
ctx.beginPath(); ctx.arc(0, 0, 20, 0, TAU); ctx.fill();
ctx.fillStyle = '#d0d0d0';
for (let i = 0; i < 5; i++){
const a = i * TAU / 5;
ctx.beginPath(); ctx.arc(Math.cos(a)*11, Math.sin(a)*11, 3.5, 0, TAU); ctx.fill();
}
ctx.restore();
// ---- Duck body ----
ctx.save();
ctx.translate(0, bob);
// tail
ctx.fillStyle = '#f5c518'; ctx.strokeStyle = '#c99a00'; ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(-60, -145);
ctx.quadraticCurveTo(-88, -150, -100, -172);
ctx.quadraticCurveTo(-90, -140, -66, -112);
ctx.closePath(); ctx.fill(); ctx.stroke();
// body
const bg = ctx.createRadialGradient(-5, -145, 10, -15, -128, 70);
bg.addColorStop(0, '#ffe680'); bg.addColorStop(1, '#f2b705');
ctx.fillStyle = bg;
ctx.beginPath(); ctx.ellipse(-15, -128, 62, 41, -0.12, 0, TAU); ctx.fill(); ctx.stroke();
// neck
ctx.beginPath(); ctx.ellipse(32, -166, 18, 34, 0.3, 0, TAU);
ctx.fillStyle = '#fbd438'; ctx.fill();
ctx.restore();
// head (with extra slight bob)
const hb = bob + 1.5 * Math.sin(2*theta + 0.7);
ctx.save();
ctx.translate(0, hb);
// scarf tail flowing back
const wave = p * TAU * 16;
ctx.fillStyle = '#2bb3c0';
ctx.beginPath();
const N = 9, pts = [];
for (let i = 0; i <= N; i++){
const x = 18 - i * 11;
const y = -168 + i * 1.8 + Math.sin(i*0.8 - wave) * i * 0.9;
pts.push({x, y, w: 7 - i * 0.45});
}
ctx.moveTo(pts[0].x, pts[0].y - pts[0].w);
for (const q of pts) ctx.lineTo(q.x, q.y - q.w);
for (let i = pts.length - 1; i >= 0; i--) ctx.lineTo(pts[i].x, pts[i].y + pts[i].w);
ctx.closePath(); ctx.fill();
// scarf wrap
ctx.fillStyle = '#1f9aa6';
ctx.beginPath(); ctx.ellipse(28, -166, 21, 9, 0.15, 0, TAU); ctx.fill();
ctx.fillStyle = '#2bb3c0';
ctx.beginPath(); ctx.ellipse(28, -168, 20, 6, 0.15, 0, TAU); ctx.fill();
// head
const hg = ctx.createRadialGradient(36, -210, 5, 42, -198, 34);
hg.addColorStop(0, '#fff09a'); hg.addColorStop(1, '#f5c518');
ctx.fillStyle = hg; ctx.strokeStyle = '#c99a00'; ctx.lineWidth = 2;
ctx.beginPath(); ctx.arc(42, -198, 30, 0, TAU); ctx.fill(); ctx.stroke();
// beak
ctx.fillStyle = '#ff8c1a'; ctx.strokeStyle = '#c96400'; ctx.lineWidth = 1.5;
ctx.beginPath();
ctx.moveTo(64, -206);
ctx.quadraticCurveTo(98, -208, 100, -196);
ctx.quadraticCurveTo(84, -193, 64, -194);
ctx.closePath(); ctx.fill(); ctx.stroke();
ctx.fillStyle = '#f07a0a';
ctx.beginPath();
ctx.moveTo(64, -194);
ctx.quadraticCurveTo(90, -193, 92, -189);
ctx.quadraticCurveTo(80, -183, 64, -187);
ctx.closePath(); ctx.fill(); ctx.stroke();
// cheek
ctx.fillStyle = 'rgba(255,120,120,0.35)';
ctx.beginPath(); ctx.ellipse(44, -186, 8, 5, 0, 0, TAU); ctx.fill();
// eye
const blink = (Math.abs(p - 0.3) < 0.012) || (Math.abs(p - 0.78) < 0.012);
if (blink){
ctx.strokeStyle = '#3a2a10'; ctx.lineWidth = 2.5;
ctx.beginPath(); ctx.arc(53, -203, 7, 0.2, Math.PI - 0.2); ctx.stroke();
} else {
ctx.fillStyle = '#fff';
ctx.beginPath(); ctx.arc(53, -202, 8, 0, TAU); ctx.fill();
ctx.fillStyle = '#1a1a1a';
ctx.beginPath(); ctx.arc(56, -202, 4.8, 0, TAU); ctx.fill();
ctx.fillStyle = '#fff';
ctx.beginPath(); ctx.arc(57.5, -204, 1.7, 0, TAU); ctx.fill();
}
// helmet
ctx.fillStyle = '#e8465c'; ctx.strokeStyle = '#b3283c'; ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(8, -208);
ctx.quadraticCurveTo(14, -246, 44, -244);
ctx.quadraticCurveTo(72, -240, 74, -212);
ctx.quadraticCurveTo(44, -218, 8, -208);
ctx.closePath(); ctx.fill(); ctx.stroke();
ctx.fillStyle = '#fff';
ctx.beginPath(); ctx.ellipse(32, -236, 6, 2.5, -0.3, 0, TAU); ctx.fill();
ctx.beginPath(); ctx.ellipse(48, -238, 6, 2.5, 0.1, 0, TAU); ctx.fill();
ctx.strokeStyle = '#333'; ctx.lineWidth = 1.5;
ctx.beginPath(); ctx.moveTo(24, -211); ctx.lineTo(34, -178); ctx.stroke();
ctx.restore();
// near crank, pedal, leg
const nearPedal = drawPedalArm(theta, '#3a3a3a');
drawLeg(hip, nearPedal, '#ff8c1a', '#c96400');
// near wing
drawWing({x: 8, y: -138 + bob}, GRIP, '#f5c518', '#c99a00');
ctx.restore();
}
// ---- Main loop ----
let start = null;
function frame(now){
if (start === null) start = now;
const t = ((now - start) / 1000) % T;
const p = t / T;
ctx.setTransform(dpr * s, 0, 0, dpr * s, 0, 0);
drawSky(p);
drawClouds(p);
drawMountains(p);
drawHills(p);
drawTrees(p);
drawGround(p);
drawScene(p);
drawForeground(p);
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
</script>
</body>
</html>