Spaces:
Paused
Paused
File size: 77,277 Bytes
6855c38 20e791f 6855c38 20e791f c174bde 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 c174bde 6855c38 20e791f 6855c38 c174bde 20e791f 6855c38 20e791f 6855c38 c174bde 20e791f 6855c38 20e791f 6855c38 c174bde 4d559be c58db7d 6855c38 4d559be 6855c38 20e791f 6855c38 c174bde 6855c38 c174bde 20e791f 6855c38 20e791f 6855c38 c174bde 20e791f 6855c38 20e791f 6855c38 c58db7d 20e791f c58db7d 6855c38 20e791f 6855c38 20e791f c58db7d 20e791f c58db7d 20e791f c58db7d 20e791f 6855c38 20e791f c58db7d 20e791f 6855c38 20e791f c174bde 20e791f 6855c38 20e791f c174bde 4d559be 20e791f 6855c38 20e791f 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 20e791f c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 20e791f c174bde 6855c38 c174bde 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f c174bde 6855c38 20e791f 6855c38 20e791f 6855c38 c174bde 6855c38 c174bde 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 20e791f 6855c38 20e791f 6855c38 c174bde 6855c38 20e791f 6855c38 c174bde 6855c38 20e791f 6855c38 20e791f 6855c38 c174bde 6855c38 c174bde 20e791f 6855c38 c174bde 6855c38 20e791f c174bde 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f c174bde 6855c38 c174bde 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 c174bde 6855c38 20e791f 6855c38 c174bde 6855c38 20e791f 6855c38 20e791f 6855c38 c174bde 6855c38 20e791f 6855c38 c174bde 6855c38 c174bde 6855c38 20e791f 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 20e791f 6855c38 c174bde 6855c38 20e791f 6855c38 20e791f 6855c38 c174bde 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 c174bde 6855c38 20e791f 6855c38 20e791f 6855c38 c174bde 6855c38 20e791f 6855c38 20e791f 6855c38 c174bde 6855c38 20e791f 6855c38 20e791f 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 20e791f 6855c38 20e791f c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 20e791f 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 c174bde 6855c38 20e791f 6855c38 20e791f c174bde 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f c174bde 20e791f c174bde 624ddb0 20e791f c174bde 20e791f 6855c38 c174bde 624ddb0 20e791f 624ddb0 6855c38 c174bde 6855c38 20e791f 6855c38 c174bde 20e791f 6855c38 20e791f c174bde 20e791f c174bde 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 c174bde 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 6855c38 20e791f 624ddb0 6855c38 c174bde 6855c38 c174bde 20e791f 6855c38 20e791f c174bde 6855c38 20e791f 6855c38 20e791f c174bde 624ddb0 c174bde 20e791f 4d559be 624ddb0 4d559be 624ddb0 4d559be 624ddb0 4d559be 624ddb0 4d559be 624ddb0 4d559be c58db7d 624ddb0 | 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 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 | // 主角「阿飞」v3 — redrawn from the protagonist of the reference footage:
// a young man with a big mop of curly black hair, a deep-blue long-sleeve
// sweater, grey trousers, white-soled sneakers, and his black classic
// motorcycle (round headlight, two round mirrors, red tail light).
//
// v3: everything is built on ONE rig.
// • The bike exposes anchor points (seat / grip / peg) in its own units.
// • The rider's limbs are solved with two-bone IK onto those anchors, so
// hands are always on the grips, feet on the pegs, hips on the seat.
// • Rider and bike share one scale: standing height h = HERO_H * bike scale s.
// • Draw order is explicit (far limbs → bike → body → near limbs), so
// nothing pokes through the bike.
import { glowBlob, lightCone } from './draw'
import { clamp, fract, hash, rgba } from './util'
type C2D = CanvasRenderingContext2D
interface V {
x: number
y: number
}
export const HERO = {
skin: '#ecd0a8',
skinShade: '#c49f7c',
blush: '#e89a86',
hair: '#121411',
hairHi: '#44596f',
line: '#08090c',
sweater: '#2f5072',
sweaterShade: '#223a54',
sweaterHi: '#4a74a0',
rib: '#264262',
pants: '#8d9298',
pantsShade: '#666b72',
shoe: '#1d1d21',
sole: '#e4ded2',
bike: '#15171c',
bikeShade: '#0b0c10',
bikeHi: '#56606f',
chrome: '#cfd6de',
chromeShade: '#7e8894',
seat: '#221c19',
tire: '#0a0a0c',
}
/** active palette (lets the same rig draw other characters, e.g. the stall auntie) */
let C: typeof HERO = HERO
export function withPalette(p: Partial<typeof HERO>, fn: () => void) {
const prev = C
C = { ...HERO, ...p }
try {
fn()
} finally {
C = prev
}
}
export const AUNTIE: Partial<typeof HERO> = {
sweater: '#8a3a3a',
sweaterShade: '#6a2a2c',
sweaterHi: '#b0585a',
rib: '#5a2426',
pants: '#2f3440',
pantsShade: '#22262f',
hair: '#3a3a3c',
hairHi: '#6a6a70',
skin: '#e2c09a',
}
export const RIVAL: Partial<typeof HERO> = {
sweater: '#17181c',
sweaterShade: '#0e0f12',
sweaterHi: '#3a3c44',
rib: '#25262c',
}
/** standing height of the hero in bike units (bike wheelbase = 1) */
export const HERO_H = 1.4
/** total height of rider + bike in bike units (for layout) */
export const RIDE_TOP = 1.5
// ------------------------------------------------------------------ geometry helpers
const add = (a: V, b: V): V => ({ x: a.x + b.x, y: a.y + b.y })
const lerpV = (a: V, b: V, k: number): V => ({ x: a.x + (b.x - a.x) * k, y: a.y + (b.y - a.y) * k })
/** Two-bone IK. bend: -1 / +1 picks which side the joint goes. Returns joint + end. */
export function ik(a: V, target: V, l1: number, l2: number, bend: number): { j: V; e: V } {
const dx = target.x - a.x
const dy = target.y - a.y
let d = Math.hypot(dx, dy)
const ang = Math.atan2(dy, dx)
d = clamp(d, Math.abs(l1 - l2) + 1e-4, l1 + l2 - 1e-4)
const cosA = (l1 * l1 + d * d - l2 * l2) / (2 * l1 * d)
const A = Math.acos(clamp(cosA, -1, 1))
const ja = ang + bend * A
const j = { x: a.x + Math.cos(ja) * l1, y: a.y + Math.sin(ja) * l1 }
const ea = Math.atan2(target.y - j.y, target.x - j.x)
return { j, e: { x: j.x + Math.cos(ea) * l2, y: j.y + Math.sin(ea) * l2 } }
}
/** tapered capsule between two points (limbs) */
function capsulePath(ctx: C2D, a: V, b: V, ra: number, rb: number) {
const ang = Math.atan2(b.y - a.y, b.x - a.x)
const px = Math.cos(ang + Math.PI / 2)
const py = Math.sin(ang + Math.PI / 2)
ctx.beginPath()
ctx.moveTo(a.x + px * ra, a.y + py * ra)
ctx.lineTo(b.x + px * rb, b.y + py * rb)
ctx.arc(b.x, b.y, rb, ang + Math.PI / 2, ang - Math.PI / 2, true)
ctx.lineTo(a.x - px * ra, a.y - py * ra)
ctx.arc(a.x, a.y, ra, ang - Math.PI / 2, ang + Math.PI / 2, true)
ctx.closePath()
}
export function ink(ctx: C2D, fill: string, lw: number) {
ctx.fillStyle = fill
ctx.fill()
if (lw > 0) {
ctx.strokeStyle = C.line
ctx.lineWidth = lw
ctx.lineJoin = 'round'
ctx.stroke()
}
}
export function capsule(ctx: C2D, a: V, b: V, ra: number, rb: number, fill: string, lw: number) {
capsulePath(ctx, a, b, ra, rb)
ink(ctx, fill, lw)
}
export function circle(ctx: C2D, c: V, r: number, fill: string, lw: number) {
ctx.beginPath()
ctx.arc(c.x, c.y, r, 0, Math.PI * 2)
ink(ctx, fill, lw)
}
// ------------------------------------------------------------------ hair
/** Curly mop. local: centre (cx,cy), radius r, facing +1/-1, or front view. */
function curls(ctx: C2D, cx: number, cy: number, r: number, facing: number, wind: number, t: number, mode: 'side' | 'front' | 'back') {
const pts: { x: number; y: number; r: number }[] = []
const n = mode === 'back' ? 30 : 32
for (let i = 0; i < n; i++) {
let a: number
if (mode === 'front') a = Math.PI * 0.9 + (i / (n - 1)) * Math.PI * 1.2
else if (mode === 'back') a = (i / n) * Math.PI * 2
else a = -Math.PI / 2 - facing * (-0.85 + (i / (n - 1)) * 3.05) // forehead → crown → nape
if (mode === 'back' && Math.sin(a) > 0.82) continue
const k = 1.02 + 0.14 * hash(i * 3.7)
const wob = Math.sin(t * 9 + i * 1.7) * wind * 0.05
const blow = mode === 'side' ? -facing * wind * r * (0.2 + 0.4 * (1 - Math.abs(Math.sin(a)))) : mode === 'back' ? 0 : 0
const lift = mode === 'back' ? -wind * r * 0.18 * (1 - Math.sin(a)) : 0
pts.push({
x: cx + Math.cos(a) * r * k + blow + wob * r,
y: cy + Math.sin(a) * r * k * (mode === 'front' ? 0.95 : 1) + wob * r * 0.5 + lift,
r: r * (0.34 + 0.16 * hash(i * 1.3)),
})
}
const inner = 10
for (let i = 0; i < inner; i++) {
let a: number
if (mode === 'front') a = Math.PI * 1.05 + (i / (inner - 1)) * Math.PI * 0.9
else if (mode === 'back') a = (i / inner) * Math.PI * 2
else a = -Math.PI / 2 - facing * (-0.3 + (i / (inner - 1)) * 1.9)
pts.push({ x: cx + Math.cos(a) * r * 0.6 - (mode === 'side' ? facing * wind * r * 0.2 : 0), y: cy + Math.sin(a) * r * 0.6 - r * 0.05, r: r * (0.32 + 0.12 * hash(i * 7.9)) })
}
const crown = () => {
if (mode === 'front') {
ctx.moveTo(cx + r * 0.95, cy - r * 0.5)
ctx.ellipse(cx, cy - r * 0.5, r * 0.95, r * 0.5, 0, 0, Math.PI * 2)
} else if (mode === 'back') {
ctx.moveTo(cx + r, cy)
ctx.ellipse(cx, cy - r * 0.05, r * 1.0, r * 0.95, 0, 0, Math.PI * 2)
} else {
const ccx = cx - facing * r * (0.22 + wind * 0.12)
ctx.moveTo(ccx + r * 0.8, cy - r * 0.3)
ctx.ellipse(ccx, cy - r * 0.3, r * 0.8, r * 0.62, 0, 0, Math.PI * 2)
const bx = cx - facing * r * (0.45 + wind * 0.15)
ctx.moveTo(bx + r * 0.62, cy + r * 0.1)
ctx.ellipse(bx, cy + r * 0.1, r * 0.62, r * 0.8, 0, 0, Math.PI * 2)
}
}
// ink outline: same shapes, slightly larger, in line colour
const lw = Math.max(1, r * 0.07)
ctx.fillStyle = C.line
ctx.beginPath()
for (const p of pts) {
ctx.moveTo(p.x + p.r + lw, p.y)
ctx.arc(p.x, p.y, p.r + lw, 0, Math.PI * 2)
}
ctx.fill()
ctx.fillStyle = C.hair
ctx.beginPath()
for (const p of pts) {
ctx.moveTo(p.x + p.r, p.y)
ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2)
}
crown()
ctx.fill()
// curl texture: highlight crescent on each curl (light from top-front)
ctx.strokeStyle = C.hairHi
ctx.lineWidth = Math.max(1, r * 0.075)
ctx.lineCap = 'round'
ctx.beginPath()
for (const p of pts) {
const rr = p.r * 0.6
const a0 = mode === 'side' ? (facing > 0 ? -2.3 : -2.6) : -2.6
ctx.moveTo(p.x + rr * Math.cos(a0), p.y + rr * Math.sin(a0))
ctx.arc(p.x, p.y, rr, a0, a0 + 2.0)
}
ctx.stroke()
}
// ------------------------------------------------------------------ heads
export interface HeadOpts {
wind?: number
t?: number
eyes?: 'closed' | 'open'
smile?: boolean
rim?: string
tilt?: number
scarf?: string
hair?: HairStyle
mood?: 'calm' | 'angry'
}
export type HairStyle = 'curly' | 'short' | 'long' | 'ponytail' | 'bun' | 'bald' | 'cap' | 'hat'
/** Side-view head. (cx,cy) = head centre, r = head radius. facing 1 = looking right. */
export function heroHead(ctx: C2D, cx: number, cy: number, r: number, facing: number, o: HeadOpts = {}) {
const t = o.t ?? 0
const wind = o.wind ?? 0
const lw = Math.max(1, r * 0.06)
ctx.save()
ctx.translate(cx, cy)
ctx.rotate((o.tilt ?? 0) * facing)
ctx.scale(facing, 1)
// face + profile (local facing +x)
ctx.beginPath()
ctx.moveTo(-r * 0.55, -r * 0.7)
ctx.quadraticCurveTo(r * 0.55, -r * 1.0, r * 0.8, -r * 0.25)
ctx.quadraticCurveTo(r * 0.86, -r * 0.08, r * 0.98, r * 0.12) // nose
ctx.quadraticCurveTo(r * 0.92, r * 0.26, r * 0.8, r * 0.28)
ctx.lineTo(r * 0.78, r * 0.5)
ctx.quadraticCurveTo(r * 0.72, r * 0.86, r * 0.32, r * 0.9) // chin / jaw
ctx.quadraticCurveTo(-r * 0.2, r * 0.9, -r * 0.5, r * 0.55)
ctx.quadraticCurveTo(-r * 0.85, r * 0.1, -r * 0.55, -r * 0.7)
ctx.closePath()
ink(ctx, C.skin, lw)
// jaw shade
ctx.fillStyle = rgba(C.skinShade, 0.45)
ctx.beginPath()
ctx.moveTo(-r * 0.5, r * 0.55)
ctx.quadraticCurveTo(-r * 0.1, r * 0.92, r * 0.32, r * 0.9)
ctx.quadraticCurveTo(r * 0.0, r * 0.7, -r * 0.3, r * 0.3)
ctx.closePath()
ctx.fill()
// ear
ctx.beginPath()
ctx.ellipse(-r * 0.12, r * 0.14, r * 0.15, r * 0.21, 0, 0, Math.PI * 2)
ink(ctx, C.skinShade, lw * 0.8)
// eye
ctx.strokeStyle = '#21160f'
ctx.fillStyle = '#21160f'
ctx.lineWidth = Math.max(1, r * 0.075)
ctx.lineCap = 'round'
const ex = r * 0.5
const ey = r * 0.02
const angry = o.mood === 'angry'
ctx.beginPath()
if (angry) {
// narrowed, glaring eye under a heavy lid
ctx.ellipse(ex + r * 0.02, ey + r * 0.01, r * 0.08, r * 0.05, 0, 0, Math.PI * 2)
ctx.fill()
ctx.lineWidth = Math.max(1, r * 0.06)
ctx.beginPath()
ctx.moveTo(ex - r * 0.12, ey - r * 0.08)
ctx.lineTo(ex + r * 0.14, ey - r * 0.02)
ctx.stroke()
} else if ((o.eyes ?? 'closed') === 'closed') {
ctx.arc(ex, ey - r * 0.06, r * 0.15, Math.PI * 0.18, Math.PI * 0.82)
ctx.stroke()
} else {
ctx.ellipse(ex, ey, r * 0.075, r * 0.11, 0, 0, Math.PI * 2)
ctx.fill()
ctx.fillStyle = '#ffffff'
ctx.beginPath()
ctx.arc(ex + r * 0.025, ey - r * 0.04, r * 0.028, 0, Math.PI * 2)
ctx.fill()
}
// thick brow (angry: pulled down hard toward the nose)
ctx.lineWidth = Math.max(1.5, r * (angry ? 0.13 : 0.1))
ctx.beginPath()
if (angry) {
ctx.moveTo(ex - r * 0.2, ey - r * 0.3)
ctx.lineTo(ex + r * 0.2, ey - r * 0.12)
} else {
ctx.moveTo(ex - r * 0.17, ey - r * 0.24)
ctx.lineTo(ex + r * 0.15, ey - r * 0.28)
}
ctx.stroke()
if (angry) {
// nose-bridge crease
ctx.lineWidth = Math.max(1, r * 0.04)
ctx.beginPath()
ctx.moveTo(r * 0.72, -r * 0.16)
ctx.lineTo(r * 0.8, -r * 0.06)
ctx.stroke()
}
// mouth
ctx.lineWidth = Math.max(1, r * 0.06)
ctx.beginPath()
if (angry) {
// gritted teeth, mouth pulled down
ctx.fillStyle = '#f4f0e8'
ctx.fillRect(r * 0.5, r * 0.5, r * 0.24, r * 0.09)
ctx.strokeRect(r * 0.5, r * 0.5, r * 0.24, r * 0.09)
ctx.beginPath()
ctx.moveTo(r * 0.5, r * 0.545)
ctx.lineTo(r * 0.74, r * 0.545)
ctx.moveTo(r * 0.47, r * 0.62)
ctx.lineTo(r * 0.52, r * 0.6)
ctx.stroke()
} else if (o.smile) ctx.arc(r * 0.6, r * 0.5, r * 0.11, 0.15, Math.PI * 0.75)
else {
ctx.moveTo(r * 0.55, r * 0.56)
ctx.lineTo(r * 0.7, r * 0.54)
}
ctx.stroke()
// blush
ctx.fillStyle = rgba(C.blush, 0.22)
ctx.beginPath()
ctx.ellipse(r * 0.38, r * 0.32, r * 0.14, r * 0.08, 0, 0, Math.PI * 2)
ctx.fill()
if (o.scarf) {
// headscarf over the hair, knot at the nape
ctx.beginPath()
ctx.moveTo(r * 0.55, -r * 0.55)
ctx.quadraticCurveTo(r * 0.1, -r * 1.25, -r * 0.75, -r * 0.55)
ctx.quadraticCurveTo(-r * 0.95, r * 0.1, -r * 0.55, r * 0.45)
ctx.lineTo(-r * 0.3, r * 0.1)
ctx.quadraticCurveTo(r * 0.05, -r * 0.6, r * 0.55, -r * 0.55)
ctx.closePath()
ink(ctx, o.scarf, lw)
ctx.beginPath()
ctx.moveTo(-r * 0.7, r * 0.25)
ctx.lineTo(-r * 1.05, r * 0.55)
ctx.lineTo(-r * 0.75, r * 0.6)
ctx.closePath()
ink(ctx, o.scarf, lw)
} else if (o.hair && o.hair !== 'curly') sideHair(ctx, r, o.hair, lw, t)
else curls(ctx, -r * 0.05, -r * 0.14, r, 1, wind, t, 'side')
if (o.rim) {
ctx.strokeStyle = o.rim
ctx.lineWidth = Math.max(1, r * 0.08)
ctx.beginPath()
ctx.arc(-r * 0.05, -r * 0.2, r * 1.2, Math.PI * 1.05, Math.PI * 1.5)
ctx.stroke()
}
ctx.restore()
}
// ------------------------------------------------------------------ body pieces (side view)
export interface Pose {
hip: V
sh: V
head: V
headR: number
kneeN: V
footN: V
kneeF: V
footF: V
elbowN: V
handN: V
elbowF: V
handF: V
}
export function torso(ctx: C2D, hip: V, sh: V, h: number, f: number, lw: number) {
// sweater body: a rounded slab between hip and shoulder
const ux = sh.x - hip.x
const uy = sh.y - hip.y
const L = Math.hypot(ux, uy) || 1
const nx = -uy / L
const ny = ux / L
// n points to the "front" when facing +x? make sure:
const s = nx * f > 0 ? 1 : -1
const fx = nx * s
const fy = ny * s
const wF = h * 0.11
const wB = h * 0.105
const p0 = { x: hip.x + fx * wF * 0.9 + (ux / L) * -h * 0.03, y: hip.y + fy * wF * 0.9 + (uy / L) * -h * 0.03 }
const p1 = { x: sh.x + fx * wF * 0.95, y: sh.y + fy * wF * 0.95 }
const p2 = { x: sh.x - fx * wB, y: sh.y - fy * wB }
const p3 = { x: hip.x - fx * wB + (ux / L) * -h * 0.03, y: hip.y - fy * wB + (uy / L) * -h * 0.03 }
ctx.beginPath()
ctx.moveTo(p0.x, p0.y)
ctx.quadraticCurveTo((p0.x + p1.x) / 2 + fx * h * 0.02, (p0.y + p1.y) / 2 + fy * h * 0.02, p1.x, p1.y)
ctx.quadraticCurveTo(sh.x + (ux / L) * h * 0.05, sh.y + (uy / L) * h * 0.05, p2.x, p2.y)
ctx.quadraticCurveTo((p2.x + p3.x) / 2 - fx * h * 0.025, (p2.y + p3.y) / 2 - fy * h * 0.025, p3.x, p3.y)
ctx.closePath()
ink(ctx, C.sweater, lw)
// back shading
ctx.fillStyle = rgba(C.sweaterShade, 0.9)
ctx.beginPath()
ctx.moveTo(p3.x, p3.y)
ctx.quadraticCurveTo((p2.x + p3.x) / 2 - fx * h * 0.025, (p2.y + p3.y) / 2 - fy * h * 0.025, p2.x, p2.y)
ctx.lineTo(sh.x - fx * wB * 0.35, sh.y - fy * wB * 0.35)
ctx.lineTo(hip.x - fx * wB * 0.3, hip.y - fy * wB * 0.3)
ctx.closePath()
ctx.fill()
// knit texture lines
ctx.strokeStyle = rgba(C.sweaterHi, 0.35)
ctx.lineWidth = Math.max(1, h * 0.004)
ctx.beginPath()
for (let k = 1; k < 4; k++) {
const q = k / 4
const a = lerpV(p0, p1, q)
const b = lerpV(p3, p2, q)
ctx.moveTo(a.x - fx * h * 0.02, a.y - fy * h * 0.02)
ctx.lineTo(lerpV(a, b, 0.55).x, lerpV(a, b, 0.55).y)
}
ctx.stroke()
// ribbed hem
capsule(ctx, { x: p3.x + (ux / L) * h * 0.02, y: p3.y + (uy / L) * h * 0.02 }, { x: p0.x + (ux / L) * h * 0.02, y: p0.y + (uy / L) * h * 0.02 }, h * 0.018, h * 0.018, C.rib, lw)
}
export function legPiece(ctx: C2D, hip: V, knee: V, foot: V, h: number, f: number, near: boolean, lw: number) {
const col = near ? C.pants : C.pantsShade
capsule(ctx, hip, knee, h * 0.052, h * 0.045, col, lw)
capsule(ctx, knee, foot, h * 0.045, h * 0.037, col, lw)
// knee crease
ctx.strokeStyle = rgba(C.line, 0.35)
ctx.lineWidth = Math.max(1, h * 0.004)
ctx.beginPath()
ctx.moveTo(knee.x - h * 0.02 * f, knee.y - h * 0.01)
ctx.lineTo(knee.x + h * 0.01 * f, knee.y + h * 0.015)
ctx.stroke()
shoe(ctx, foot, h, f, lw)
}
export function shoe(ctx: C2D, foot: V, h: number, f: number, lw: number) {
ctx.beginPath()
ctx.moveTo(foot.x - h * 0.035 * f, foot.y - h * 0.02)
ctx.quadraticCurveTo(foot.x + h * 0.02 * f, foot.y - h * 0.045, foot.x + h * 0.075 * f, foot.y - h * 0.008)
ctx.lineTo(foot.x + h * 0.08 * f, foot.y + h * 0.012)
ctx.lineTo(foot.x - h * 0.04 * f, foot.y + h * 0.012)
ctx.closePath()
ink(ctx, C.shoe, lw)
ctx.fillStyle = C.sole
ctx.fillRect(Math.min(foot.x - h * 0.04 * f, foot.x + h * 0.08 * f), foot.y + h * 0.003, h * 0.12, h * 0.012)
}
export function armPiece(ctx: C2D, sh: V, elbow: V, hand: V, h: number, near: boolean, lw: number) {
const col = near ? C.sweater : C.sweaterShade
capsule(ctx, sh, elbow, h * 0.04, h * 0.035, col, lw)
capsule(ctx, elbow, hand, h * 0.035, h * 0.031, col, lw)
// ribbed cuff
const c = lerpV(elbow, hand, 0.86)
capsule(ctx, lerpV(elbow, hand, 0.78), c, h * 0.033, h * 0.033, C.rib, lw)
circle(ctx, hand, h * 0.03, C.skin, lw)
}
function drawFar(ctx: C2D, p: Pose, h: number, f: number, lw: number) {
legPiece(ctx, p.hip, p.kneeF, p.footF, h, f, false, lw)
armPiece(ctx, p.sh, p.elbowF, p.handF, h, false, lw)
}
function drawNear(ctx: C2D, p: Pose, h: number, f: number, lw: number, o: HeadOpts) {
// neck
capsule(ctx, p.sh, { x: p.head.x - f * p.headR * 0.1, y: p.head.y + p.headR * 0.6 }, h * 0.034, h * 0.032, C.skinShade, lw)
torso(ctx, p.hip, p.sh, h, f, lw)
legPiece(ctx, p.hip, p.kneeN, p.footN, h, f, true, lw)
heroHead(ctx, p.head.x, p.head.y, p.headR, f, o)
armPiece(ctx, p.sh, p.elbowN, p.handN, h, true, lw)
}
const LEG1 = 0.21
const LEG2 = 0.205
const ARM1 = 0.15
const ARM2 = 0.14
const TORSO = 0.25
function headFor(sh: V, h: number, f: number, lean: number): { head: V; r: number } {
const r = h * 0.14
return { head: { x: sh.x + f * (h * 0.03 + Math.sin(lean) * h * 0.05), y: sh.y - h * 0.035 - r * 0.95 }, r }
}
// ------------------------------------------------------------------ walking / standing
export interface HeroWalkOpts {
facing?: number
run?: number
rim?: string
t?: number
eyes?: 'closed' | 'open'
scarf?: string
/** world-space hand targets (e.g. bike grips) */
gripN?: V
gripF?: V
stand?: boolean
}
export function walkPose(x: number, y: number, h: number, phase: number, o: HeroWalkOpts): Pose {
const f = o.facing ?? 1
const run = o.run ?? 0
const P = Math.PI * 2
const bob = Math.abs(Math.cos(phase * P)) * h * (0.012 + run * 0.02)
const hip = { x, y: y - h * 0.4 + bob * 0.6 - h * 0.012 }
const lean = 0.04 + run * 0.25
const sh = { x: hip.x + f * Math.sin(lean) * h * TORSO, y: hip.y - Math.cos(lean) * h * TORSO }
const stride = h * (0.13 + run * 0.08)
const foot = (ph: number): V => {
const s = Math.sin(ph * P)
const lift = Math.max(0, Math.cos(ph * P)) * h * (0.045 + run * 0.06)
return { x: x + f * s * stride, y: y - lift }
}
const fN = o.stand ? { x: x + f * h * 0.05, y } : foot(phase)
const fF = o.stand ? { x: x - f * h * 0.04, y } : foot(phase + 0.5)
const legN = ik(hip, fN, h * LEG1, h * LEG2, -f)
const legF = ik(hip, fF, h * LEG1, h * LEG2, -f)
const handSwing = (ph: number): V => {
const s = Math.sin(ph * P)
return { x: sh.x + f * s * h * (0.1 + run * 0.08), y: sh.y + h * (0.25 - run * 0.08) }
}
const tN = o.gripN ?? handSwing(phase + 0.5)
const tF = o.gripF ?? handSwing(phase)
const armN = ik(sh, tN, h * ARM1, h * ARM2, f)
const armF = ik(sh, tF, h * ARM1, h * ARM2, f)
const hd = headFor(sh, h, f, lean)
return {
hip,
sh,
head: hd.head,
headR: hd.r,
kneeN: legN.j,
footN: legN.e,
kneeF: legF.j,
footF: legF.e,
elbowN: armN.j,
handN: armN.e,
elbowF: armF.j,
handF: armF.e,
}
}
/** Side-view walking hero. (x,y) = feet on ground, h = total height. */
export function heroWalk(ctx: C2D, x: number, y: number, h: number, phase: number, o: HeroWalkOpts = {}): Pose {
const f = o.facing ?? 1
const lw = Math.max(1, h * 0.007)
const p = walkPose(x, y, h, phase, o)
contactShadow(ctx, x, y, h * 0.2)
drawFar(ctx, p, h, f, lw)
drawNear(ctx, p, h, f, lw, { t: o.t, wind: (o.run ?? 0) * 0.6 + 0.1, eyes: o.eyes ?? 'closed', rim: o.rim, scarf: o.scarf })
return p
}
function contactShadow(ctx: C2D, x: number, y: number, w: number) {
ctx.fillStyle = 'rgba(0,0,0,0.45)'
ctx.beginPath()
ctx.ellipse(x, y + w * 0.03, w, w * 0.12, 0, 0, Math.PI * 2)
ctx.fill()
}
// ------------------------------------------------------------------ the motorcycle
export interface BikeOpts {
facing?: number
light?: number
spin?: number
t?: number
beam?: boolean
/** show the side stand (parked) */
parked?: boolean
}
/** anchor points of the bike, local units (wheelbase = 1, ground y = 0, facing +x) */
const ANCHOR = {
seat: { x: -0.2, y: -0.6 },
grip: { x: 0.27, y: -0.84 },
peg: { x: -0.1, y: -0.3 },
R: 0.23,
}
export function bikeAnchors(x: number, y: number, s: number, facing = 1) {
const m = (p: V): V => ({ x: x + p.x * s * facing, y: y + p.y * s })
return { seat: m(ANCHOR.seat), grip: m(ANCHOR.grip), peg: m(ANCHOR.peg) }
}
export function bike(ctx: C2D, x: number, y: number, s: number, o: BikeOpts = {}) {
ctx.save()
ctx.translate(x, y)
ctx.scale(o.facing ?? 1, 1)
bikeLocal(ctx, s, o)
ctx.restore()
}
function wheel(ctx: C2D, cx: number, cy: number, R: number, s: number, spin: number, front: boolean, lw: number) {
// tyre
ctx.beginPath()
ctx.arc(cx, cy, R, 0, Math.PI * 2)
ink(ctx, C.tire, lw)
ctx.strokeStyle = 'rgba(140,150,165,0.35)'
ctx.lineWidth = Math.max(1, s * 0.008)
ctx.beginPath()
ctx.arc(cx, cy, R * 0.92, Math.PI * 1.05, Math.PI * 1.55)
ctx.stroke()
// rim
ctx.strokeStyle = C.chrome
ctx.lineWidth = Math.max(1, s * 0.022)
ctx.beginPath()
ctx.arc(cx, cy, R * 0.7, 0, Math.PI * 2)
ctx.stroke()
ctx.fillStyle = '#121418'
ctx.beginPath()
ctx.arc(cx, cy, R * 0.66, 0, Math.PI * 2)
ctx.fill()
// spokes
ctx.strokeStyle = rgba(C.chrome, 0.85)
ctx.lineWidth = Math.max(1, s * 0.005)
ctx.beginPath()
for (let k = 0; k < 16; k++) {
const a = (k / 16) * Math.PI * 2 + spin
const b = a + (k % 2 ? 0.35 : -0.35)
ctx.moveTo(cx + Math.cos(a) * R * 0.1, cy + Math.sin(a) * R * 0.1)
ctx.lineTo(cx + Math.cos(b) * R * 0.66, cy + Math.sin(b) * R * 0.66)
}
ctx.stroke()
if (front) {
// brake disc
ctx.strokeStyle = rgba(C.chromeShade, 0.9)
ctx.lineWidth = Math.max(1, s * 0.03)
ctx.beginPath()
ctx.arc(cx, cy, R * 0.33, 0, Math.PI * 2)
ctx.stroke()
}
circle(ctx, { x: cx, y: cy }, R * 0.13, C.chrome, lw)
circle(ctx, { x: cx, y: cy }, R * 0.05, C.chromeShade, 0)
}
/** bike drawn at origin facing +x (ground at y = 0) */
function bikeLocal(ctx: C2D, s: number, o: BikeOpts) {
const R = s * ANCHOR.R
const rx = -s * 0.5
const fx = s * 0.5
const wy = -R
const light = o.light ?? 1
const lw = Math.max(1, s * 0.008)
const X = (dx: number) => dx * s
const Y = (dy: number) => -dy * s
const spin = o.spin ?? 0
ctx.lineCap = 'round'
ctx.lineJoin = 'round'
// ground shadow
ctx.fillStyle = 'rgba(0,0,0,0.5)'
ctx.beginPath()
ctx.ellipse(0, s * 0.01, s * 0.78, s * 0.05, 0, 0, Math.PI * 2)
ctx.fill()
if (o.beam && light > 0) lightCone(ctx, X(0.55), Y(0.72), s * 3.2, 0.17, -Math.PI / 2, '#fff1c8', 0.16 * light)
// side stand
if (o.parked) capsule(ctx, { x: X(-0.06), y: Y(0.28) }, { x: X(-0.16), y: Y(0.005) }, s * 0.012, s * 0.01, C.bikeShade, lw)
wheel(ctx, rx, wy, R, s, spin, false, lw)
wheel(ctx, fx, wy, R, s, spin, true, lw)
// swing arm
capsule(ctx, { x: X(-0.1), y: Y(0.3) }, { x: rx, y: wy }, s * 0.03, s * 0.022, C.bike, lw)
// chain
ctx.strokeStyle = '#3a3f48'
ctx.lineWidth = Math.max(1, s * 0.008)
ctx.beginPath()
ctx.moveTo(X(-0.06), Y(0.33))
ctx.lineTo(rx, wy - R * 0.32)
ctx.moveTo(X(-0.06), Y(0.27))
ctx.lineTo(rx, wy + R * 0.32)
ctx.stroke()
circle(ctx, { x: rx, y: wy }, R * 0.32, 'rgba(0,0,0,0)', lw)
// rear shock (spring)
{
const a = { x: X(-0.36), y: Y(0.58) }
const b = { x: rx + R * 0.15, y: wy - R * 0.1 }
capsule(ctx, a, b, s * 0.016, s * 0.016, C.chromeShade, lw)
ctx.strokeStyle = '#d8b04a'
ctx.lineWidth = Math.max(1, s * 0.009)
ctx.beginPath()
for (let k = 0; k <= 9; k++) {
const p = lerpV(a, b, 0.12 + (k / 9) * 0.7)
const dx = (b.y - a.y) / Math.hypot(b.x - a.x, b.y - a.y)
const dy = -(b.x - a.x) / Math.hypot(b.x - a.x, b.y - a.y)
const side = k % 2 ? 1 : -1
const q = { x: p.x + dx * s * 0.026 * side, y: p.y + dy * s * 0.026 * side }
if (k === 0) ctx.moveTo(q.x, q.y)
else ctx.lineTo(q.x, q.y)
}
ctx.stroke()
}
// frame tubes
capsule(ctx, { x: X(0.36), y: Y(0.78) }, { x: X(0.12), y: Y(0.24) }, s * 0.024, s * 0.024, C.bike, lw)
capsule(ctx, { x: X(0.36), y: Y(0.78) }, { x: X(-0.44), y: Y(0.6) }, s * 0.022, s * 0.022, C.bike, lw)
// engine: crankcase + finned cylinder
ctx.beginPath()
ctx.moveTo(X(-0.16), Y(0.44))
ctx.lineTo(X(0.12), Y(0.46))
ctx.quadraticCurveTo(X(0.22), Y(0.4), X(0.2), Y(0.24))
ctx.quadraticCurveTo(X(0.05), Y(0.15), X(-0.12), Y(0.2))
ctx.quadraticCurveTo(X(-0.2), Y(0.3), X(-0.16), Y(0.44))
ctx.closePath()
ink(ctx, '#1b1e24', lw)
ctx.save()
ctx.translate(X(0.1), Y(0.52))
ctx.rotate(0.3)
ctx.beginPath()
ctx.rect(-s * 0.075, -s * 0.11, s * 0.15, s * 0.17)
ink(ctx, '#2a2f37', lw)
ctx.strokeStyle = C.chrome
ctx.lineWidth = Math.max(1, s * 0.009)
ctx.beginPath()
for (let k = 0; k < 6; k++) {
const yy = -s * 0.095 + k * s * 0.028
ctx.moveTo(-s * 0.085, yy)
ctx.lineTo(s * 0.085, yy)
}
ctx.stroke()
ctx.restore()
circle(ctx, { x: X(0.0), y: Y(0.3) }, s * 0.075, C.chromeShade, lw)
circle(ctx, { x: X(0.0), y: Y(0.3) }, s * 0.05, C.chrome, 0)
// exhaust: header + muffler
ctx.strokeStyle = C.line
ctx.lineWidth = s * 0.05
ctx.beginPath()
ctx.moveTo(X(0.2), Y(0.5))
ctx.quadraticCurveTo(X(0.28), Y(0.22), X(0.05), Y(0.16))
ctx.lineTo(X(-0.25), Y(0.2))
ctx.stroke()
ctx.strokeStyle = C.chrome
ctx.lineWidth = s * 0.034
ctx.stroke()
capsule(ctx, { x: X(-0.22), y: Y(0.2) }, { x: X(-0.64), y: Y(0.3) }, s * 0.04, s * 0.045, C.chrome, lw)
ctx.strokeStyle = rgba('#ffffff', 0.55)
ctx.lineWidth = Math.max(1, s * 0.008)
ctx.beginPath()
ctx.moveTo(X(-0.26), Y(0.225))
ctx.lineTo(X(-0.6), Y(0.32))
ctx.stroke()
circle(ctx, { x: X(-0.64), y: Y(0.3) }, s * 0.03, '#2a2f37', lw)
// side cover under the seat
ctx.beginPath()
ctx.moveTo(X(-0.38), Y(0.58))
ctx.lineTo(X(-0.12), Y(0.6))
ctx.lineTo(X(-0.14), Y(0.42))
ctx.lineTo(X(-0.34), Y(0.44))
ctx.closePath()
ink(ctx, C.bike, lw)
circle(ctx, { x: X(-0.25), y: Y(0.51) }, s * 0.025, C.chromeShade, lw)
// rear fender + tail light + plate
ctx.beginPath()
ctx.moveTo(X(-0.4), Y(0.6))
ctx.quadraticCurveTo(X(-0.62), Y(0.62), X(-0.72), Y(0.48))
ctx.lineTo(X(-0.68), Y(0.46))
ctx.quadraticCurveTo(X(-0.6), Y(0.56), X(-0.4), Y(0.55))
ctx.closePath()
ink(ctx, C.bike, lw)
ctx.beginPath()
ctx.rect(X(-0.72), Y(0.46), s * 0.06, s * 0.08)
ink(ctx, '#e8e2d6', lw)
ctx.beginPath()
ctx.ellipse(X(-0.69), Y(0.565), s * 0.035, s * 0.022, 0, 0, Math.PI * 2)
ink(ctx, '#ff3a5c', lw)
glowBlob(ctx, X(-0.7), Y(0.565), s * 0.13, '#ff2d55', 0.85 * light)
// seat
ctx.beginPath()
ctx.moveTo(X(-0.46), Y(0.6))
ctx.quadraticCurveTo(X(-0.44), Y(0.67), X(-0.36), Y(0.66))
ctx.lineTo(X(-0.04), Y(0.64))
ctx.quadraticCurveTo(X(0.02), Y(0.62), X(0.0), Y(0.58))
ctx.lineTo(X(-0.44), Y(0.57))
ctx.closePath()
ink(ctx, C.seat, lw)
ctx.strokeStyle = 'rgba(200,180,150,0.25)'
ctx.lineWidth = Math.max(1, s * 0.004)
ctx.setLineDash([s * 0.012, s * 0.01])
ctx.beginPath()
ctx.moveTo(X(-0.4), Y(0.62))
ctx.lineTo(X(-0.04), Y(0.605))
ctx.stroke()
ctx.setLineDash([])
// fuel tank — glossy teardrop with chrome badge and knee pad
ctx.beginPath()
ctx.moveTo(X(-0.04), Y(0.6))
ctx.quadraticCurveTo(X(0.02), Y(0.77), X(0.2), Y(0.77))
ctx.quadraticCurveTo(X(0.36), Y(0.76), X(0.38), Y(0.66))
ctx.quadraticCurveTo(X(0.36), Y(0.58), X(0.22), Y(0.56))
ctx.quadraticCurveTo(X(0.06), Y(0.54), X(-0.04), Y(0.6))
ctx.closePath()
ink(ctx, C.bike, lw)
ctx.strokeStyle = rgba(C.bikeHi, 0.9)
ctx.lineWidth = Math.max(1, s * 0.014)
ctx.beginPath()
ctx.moveTo(X(0.04), Y(0.72))
ctx.quadraticCurveTo(X(0.18), Y(0.765), X(0.3), Y(0.73))
ctx.stroke()
ctx.beginPath()
ctx.ellipse(X(0.2), Y(0.66), s * 0.045, s * 0.03, 0, 0, Math.PI * 2)
ink(ctx, C.chrome, lw)
ctx.fillStyle = '#c4142f'
ctx.beginPath()
ctx.ellipse(X(0.2), Y(0.66), s * 0.026, s * 0.015, 0, 0, Math.PI * 2)
ctx.fill()
ctx.beginPath()
ctx.ellipse(X(0.04), Y(0.6), s * 0.05, s * 0.03, -0.2, 0, Math.PI * 2)
ink(ctx, '#202228', lw)
// front fork + fender
capsule(ctx, { x: X(0.37), y: Y(0.8) }, { x: fx, y: wy }, s * 0.022, s * 0.02, C.chrome, lw)
capsule(ctx, { x: X(0.44), y: Y(0.4) }, { x: X(0.49), y: Y(0.27) }, s * 0.03, s * 0.028, '#2a2e36', lw)
ctx.strokeStyle = C.line
ctx.lineWidth = s * 0.05
ctx.beginPath()
ctx.arc(fx, wy, R * 1.12, Math.PI * 1.08, Math.PI * 1.72)
ctx.stroke()
ctx.strokeStyle = C.bike
ctx.lineWidth = s * 0.034
ctx.stroke()
// handlebar + grips + lever
capsule(ctx, { x: X(0.37), y: Y(0.82) }, { x: X(0.31), y: Y(0.86) }, s * 0.011, s * 0.011, C.chrome, lw)
capsule(ctx, { x: X(0.31), y: Y(0.86) }, { x: X(0.24), y: Y(0.84) }, s * 0.018, s * 0.018, '#0e0f12', lw)
ctx.strokeStyle = C.chromeShade
ctx.lineWidth = Math.max(1, s * 0.008)
ctx.beginPath()
ctx.moveTo(X(0.31), Y(0.86))
ctx.lineTo(X(0.22), Y(0.81))
ctx.stroke()
// speedo
circle(ctx, { x: X(0.38), y: Y(0.86) }, s * 0.03, '#1a1c22', lw)
circle(ctx, { x: X(0.38), y: Y(0.86) }, s * 0.018, '#d9e2c9', 0)
// mirror
ctx.strokeStyle = C.chromeShade
ctx.lineWidth = Math.max(1, s * 0.01)
ctx.beginPath()
ctx.moveTo(X(0.32), Y(0.86))
ctx.quadraticCurveTo(X(0.29), Y(0.95), X(0.31), Y(1.0))
ctx.stroke()
ctx.beginPath()
ctx.ellipse(X(0.31), Y(1.03), s * 0.04, s * 0.032, 0, 0, Math.PI * 2)
ink(ctx, C.chrome, lw)
ctx.fillStyle = '#6d8296'
ctx.beginPath()
ctx.ellipse(X(0.31), Y(1.03), s * 0.026, s * 0.02, 0, 0, Math.PI * 2)
ctx.fill()
// headlight: chrome bucket, glass, amber indicator
ctx.beginPath()
ctx.ellipse(X(0.46), Y(0.72), s * 0.07, s * 0.08, 0, 0, Math.PI * 2)
ink(ctx, C.chrome, lw)
ctx.fillStyle = light > 0.1 ? '#fff6d8' : '#5a626c'
ctx.beginPath()
ctx.ellipse(X(0.5), Y(0.72), s * 0.035, s * 0.065, 0, 0, Math.PI * 2)
ctx.fill()
ctx.beginPath()
ctx.ellipse(X(0.4), Y(0.79), s * 0.02, s * 0.014, 0, 0, Math.PI * 2)
ink(ctx, '#ffa63a', lw)
if (light > 0.1) glowBlob(ctx, X(0.52), Y(0.72), s * 0.26, '#fff1c8', 0.9 * light)
// foot peg
capsule(ctx, { x: X(-0.13), y: Y(0.3) }, { x: X(-0.06), y: Y(0.3) }, s * 0.012, s * 0.012, C.chromeShade, lw)
}
// ------------------------------------------------------------------ pushing the bike
/** Hero walking beside (in front of) his bike, both hands on the bars. (x,y) = bike ground point. */
export function heroPush(ctx: C2D, x: number, y: number, s: number, phase: number, o: { facing?: number; t?: number; rim?: string; spin?: number; light?: number; beam?: boolean; eyes?: 'closed' | 'open' } = {}) {
const f = o.facing ?? 1
const h = HERO_H * s
const A = bikeAnchors(x, y, s, f)
const lw = Math.max(1, h * 0.007)
const px = x - f * s * 0.1
const p = walkPose(px, y, h, phase, { facing: f, gripN: A.grip, gripF: { x: A.grip.x - f * s * 0.02, y: A.grip.y - s * 0.01 } })
// far arm (to the far grip) is behind the bike
armPiece(ctx, p.sh, p.elbowF, p.handF, h, false, lw)
bike(ctx, x, y, s, { facing: f, spin: o.spin, light: o.light, beam: o.beam })
// body in front of the bike
contactShadow(ctx, px, y, h * 0.18)
legPiece(ctx, p.hip, p.kneeF, p.footF, h, f, false, lw)
drawNear(ctx, p, h, f, lw, { t: o.t, wind: 0.1, eyes: o.eyes ?? 'closed', rim: o.rim })
}
// ------------------------------------------------------------------ riding (side)
export interface RideOpts {
facing?: number
wind?: number
t?: number
spin?: number
light?: number
beam?: boolean
smile?: boolean
eyes?: 'closed' | 'open'
rim?: string
/** 0 = sitting upright (parked), 1 = tucked in (racing) */
tuck?: number
}
/** Hero riding his bike, side view. (x,y) = ground under bike centre, s = bike scale. */
export function ridePose(x: number, y: number, s: number, o: RideOpts = {}): Pose {
const f = o.facing ?? 1
const t = o.t ?? 0
const h = HERO_H * s
const A = bikeAnchors(x, y, s, f)
const bounce = Math.sin(t * 13) * s * 0.004 * (o.tuck ?? 0.5)
const hip = { x: A.seat.x, y: A.seat.y - h * 0.035 + bounce }
// choose torso lean so the hands reach the grips with a relaxed elbow
const reach = (ARM1 + ARM2) * h * (0.9 - (o.tuck ?? 0.5) * 0.1)
let best = 0.3
let err = 1e9
for (let l = 0.05; l <= 1.2; l += 0.02) {
const sh = { x: hip.x + f * Math.sin(l) * h * TORSO, y: hip.y - Math.cos(l) * h * TORSO }
const e = Math.abs(Math.hypot(A.grip.x - sh.x, A.grip.y - sh.y) - reach)
if (e < err) {
err = e
best = l
}
}
const lean = best
const sh = { x: hip.x + f * Math.sin(lean) * h * TORSO, y: hip.y - Math.cos(lean) * h * TORSO }
const legN = ik(hip, A.peg, h * LEG1, h * LEG2, -f)
const pegF = { x: A.peg.x - f * s * 0.02, y: A.peg.y - s * 0.01 }
const legF = ik(hip, pegF, h * LEG1, h * LEG2, -f)
const gripF = { x: A.grip.x - f * s * 0.02, y: A.grip.y - s * 0.012 }
const armN = ik(sh, A.grip, h * ARM1, h * ARM2, f)
const armF = ik(sh, gripF, h * ARM1, h * ARM2, f)
const hd = headFor(sh, h, f, lean)
const p: Pose = {
hip,
sh,
head: hd.head,
headR: hd.r,
kneeN: legN.j,
footN: legN.e,
kneeF: legF.j,
footF: legF.e,
elbowN: armN.j,
handN: armN.e,
elbowF: armF.j,
handF: armF.e,
}
return p
}
export function heroRide(ctx: C2D, x: number, y: number, s: number, o: RideOpts = {}) {
const f = o.facing ?? 1
const t = o.t ?? 0
const h = HERO_H * s
const lw = Math.max(1, h * 0.007)
const p = ridePose(x, y, s, o)
const hip = p.hip
// far limbs behind the bike
drawFar(ctx, p, h, f, lw)
bike(ctx, x, y, s, { facing: f, light: o.light, spin: o.spin, beam: o.beam })
// seat contact: the trousers sit on top of the seat
capsule(ctx, { x: hip.x - f * h * 0.05, y: hip.y + h * 0.01 }, { x: hip.x + f * h * 0.03, y: hip.y + h * 0.015 }, h * 0.05, h * 0.05, C.pants, lw)
drawNear(ctx, p, h, f, lw, { t, wind: o.wind ?? 0.6, smile: o.smile, eyes: o.eyes ?? 'open', rim: o.rim })
}
// ------------------------------------------------------------------ back view (standing)
export function heroBack(ctx: C2D, x: number, y: number, h: number, sway = 0, o: { rim?: string; t?: number; wind?: number } = {}) {
const lw = Math.max(1, h * 0.007)
const sw = sway * h * 0.02
const t = o.t ?? 0
contactShadow(ctx, x, y, h * 0.2)
// legs
capsule(ctx, { x: x - h * 0.05, y: y - h * 0.4 }, { x: x - h * 0.055, y: y - h * 0.03 }, h * 0.048, h * 0.038, C.pantsShade, lw)
capsule(ctx, { x: x + h * 0.05, y: y - h * 0.4 }, { x: x + h * 0.055, y: y - h * 0.03 }, h * 0.048, h * 0.038, C.pants, lw)
for (const sd of [-1, 1]) {
ctx.beginPath()
ctx.ellipse(x + sd * h * 0.055, y - h * 0.015, h * 0.045, h * 0.025, 0, 0, Math.PI * 2)
ink(ctx, C.shoe, lw)
}
// arms
for (const sd of [-1, 1]) {
capsule(ctx, { x: x + sd * h * 0.13 + sw, y: y - h * 0.63 }, { x: x + sd * h * 0.155, y: y - h * 0.4 }, h * 0.038, h * 0.032, C.sweaterShade, lw)
circle(ctx, { x: x + sd * h * 0.157, y: y - h * 0.375 }, h * 0.028, C.skin, lw)
}
// sweater
ctx.beginPath()
ctx.moveTo(x - h * 0.14 + sw, y - h * 0.67)
ctx.quadraticCurveTo(x - h * 0.16, y - h * 0.52, x - h * 0.12, y - h * 0.37)
ctx.lineTo(x + h * 0.12, y - h * 0.37)
ctx.quadraticCurveTo(x + h * 0.16, y - h * 0.52, x + h * 0.14 + sw, y - h * 0.67)
ctx.quadraticCurveTo(x + sw, y - h * 0.71, x - h * 0.14 + sw, y - h * 0.67)
ctx.closePath()
ink(ctx, C.sweater, lw)
ctx.fillStyle = rgba(C.sweaterShade, 0.8)
ctx.fillRect(x - h * 0.005, y - h * 0.66, h * 0.01, h * 0.28)
capsule(ctx, { x: x - h * 0.12, y: y - h * 0.385 }, { x: x + h * 0.12, y: y - h * 0.385 }, h * 0.018, h * 0.018, C.rib, lw)
// neck + head from behind
const r = h * 0.14
const hx = x + sw * 1.2
const hy = y - h * 0.7 - r * 0.9
capsule(ctx, { x: hx, y: y - h * 0.67 }, { x: hx, y: hy + r * 0.5 }, h * 0.026, h * 0.026, C.skinShade, lw)
for (const sd of [-1, 1]) {
ctx.beginPath()
ctx.ellipse(hx + sd * r * 0.92, hy + r * 0.15, r * 0.14, r * 0.2, 0, 0, Math.PI * 2)
ink(ctx, C.skinShade, lw)
}
curls(ctx, hx, hy, r, 1, o.wind ?? 0, t, 'back')
if (o.rim) {
ctx.strokeStyle = o.rim
ctx.lineWidth = Math.max(1, h * 0.008)
ctx.beginPath()
ctx.arc(hx, hy - r * 0.1, r * 1.22, Math.PI * 1.1, Math.PI * 1.9)
ctx.stroke()
}
}
// ------------------------------------------------------------------ riding (rear view)
/** Rear view of hero on the bike. (x,y) = ground under rear tyre, s = overall scale (≈ height of rider+bike). */
export function heroRideRear(ctx: C2D, x: number, y: number, s: number, lean: number, t: number, wind = 0.8) {
const lw = Math.max(1, s * 0.006)
ctx.save()
ctx.translate(x, y)
ctx.rotate(lean)
ctx.lineCap = 'round'
ctx.lineJoin = 'round'
// --- far: handlebar, mirrors, headlight glow ahead
glowBlob(ctx, 0, -s * 0.5, s * 0.5, '#fff1c8', 0.12)
capsule(ctx, { x: -s * 0.3, y: -s * 0.6 }, { x: s * 0.3, y: -s * 0.6 }, s * 0.01, s * 0.01, C.chrome, lw)
for (const sd of [-1, 1]) {
ctx.strokeStyle = C.chromeShade
ctx.lineWidth = Math.max(1, s * 0.008)
ctx.beginPath()
ctx.moveTo(sd * s * 0.25, -s * 0.6)
ctx.lineTo(sd * s * 0.3, -s * 0.71)
ctx.stroke()
ctx.beginPath()
ctx.ellipse(sd * s * 0.305, -s * 0.735, s * 0.034, s * 0.027, 0, 0, Math.PI * 2)
ink(ctx, C.chrome, lw)
ctx.fillStyle = '#6d8296'
ctx.beginPath()
ctx.ellipse(sd * s * 0.305, -s * 0.735, s * 0.022, s * 0.017, 0, 0, Math.PI * 2)
ctx.fill()
}
// tank glimpsed between the knees
ctx.beginPath()
ctx.ellipse(0, -s * 0.47, s * 0.09, s * 0.06, 0, 0, Math.PI * 2)
ink(ctx, C.bike, lw)
// --- rider: arms reach forward to the grips
const h = s * 0.95
for (const sd of [-1, 1]) {
const shp = { x: sd * h * 0.13, y: -s * 0.78 }
const grip = { x: sd * s * 0.27, y: -s * 0.6 }
const a = ik(shp, grip, h * 0.15, h * 0.14, sd > 0 ? -1 : 1)
capsule(ctx, shp, a.j, h * 0.04, h * 0.035, C.sweaterShade, lw)
capsule(ctx, a.j, a.e, h * 0.035, h * 0.031, C.sweaterShade, lw)
circle(ctx, a.e, h * 0.03, C.skinShade, lw)
}
// back
ctx.beginPath()
ctx.moveTo(-h * 0.16, -s * 0.47)
ctx.quadraticCurveTo(-h * 0.19, -s * 0.66, -h * 0.13, -s * 0.8)
ctx.quadraticCurveTo(0, -s * 0.84, h * 0.13, -s * 0.8)
ctx.quadraticCurveTo(h * 0.19, -s * 0.66, h * 0.16, -s * 0.47)
ctx.closePath()
ink(ctx, C.sweater, lw)
ctx.fillStyle = rgba(C.sweaterShade, 0.85)
ctx.fillRect(-h * 0.006, -s * 0.79, h * 0.012, s * 0.3)
capsule(ctx, { x: -h * 0.155, y: -s * 0.475 }, { x: h * 0.155, y: -s * 0.475 }, h * 0.018, h * 0.018, C.rib, lw)
// neck + hair
const r = h * 0.14
capsule(ctx, { x: 0, y: -s * 0.8 }, { x: 0, y: -s * 0.86 }, h * 0.026, h * 0.026, C.skinShade, lw)
curls(ctx, 0, -s * 0.84 - r * 0.85, r, 1, wind, t, 'back')
// legs out to the pegs (both sides)
for (const sd of [-1, 1]) {
const hipp = { x: sd * h * 0.08, y: -s * 0.44 }
const peg = { x: sd * s * 0.17, y: -s * 0.2 }
const k = ik(hipp, peg, h * 0.2, h * 0.19, sd > 0 ? -1 : 1)
capsule(ctx, hipp, k.j, h * 0.05, h * 0.044, sd > 0 ? C.pants : C.pantsShade, lw)
capsule(ctx, k.j, k.e, h * 0.044, h * 0.036, sd > 0 ? C.pants : C.pantsShade, lw)
ctx.beginPath()
ctx.ellipse(k.e.x + sd * h * 0.01, k.e.y + h * 0.01, h * 0.04, h * 0.03, 0, 0, Math.PI * 2)
ink(ctx, C.shoe, lw)
}
// --- near: seat edge, twin shocks, mufflers, rear tyre, fender, tail light, plate
ctx.beginPath()
ctx.ellipse(0, -s * 0.43, h * 0.13, s * 0.032, 0, 0, Math.PI * 2)
ink(ctx, C.seat, lw)
for (const sd of [-1, 1]) {
// rear shock absorbers with yellow springs
const a = { x: sd * s * 0.11, y: -s * 0.42 }
const b = { x: sd * s * 0.1, y: -s * 0.17 }
capsule(ctx, a, b, s * 0.014, s * 0.014, C.chromeShade, lw)
ctx.strokeStyle = '#d8b04a'
ctx.lineWidth = Math.max(1, s * 0.008)
ctx.beginPath()
for (let k = 0; k <= 8; k++) {
const p = lerpV(a, b, 0.1 + (k / 8) * 0.75)
ctx[k ? 'lineTo' : 'moveTo'](p.x + (k % 2 ? 1 : -1) * s * 0.022, p.y)
}
ctx.stroke()
// muffler on each side
capsule(ctx, { x: sd * s * 0.17, y: -s * 0.16 }, { x: sd * s * 0.19, y: -s * 0.25 }, s * 0.036, s * 0.042, C.chrome, lw)
circle(ctx, { x: sd * s * 0.19, y: -s * 0.25 }, s * 0.024, '#2a2f37', lw)
}
// fat rear tyre with tread
ctx.beginPath()
ctx.ellipse(0, -s * 0.15, s * 0.085, s * 0.16, 0, 0, Math.PI * 2)
ink(ctx, C.tire, lw)
ctx.strokeStyle = 'rgba(140,150,165,0.4)'
ctx.lineWidth = Math.max(1, s * 0.006)
ctx.beginPath()
for (let k = 0; k < 6; k++) {
const yy = -s * 0.27 + k * s * 0.045 + ((t * 40) % 1) * s * 0.045
ctx.moveTo(-s * 0.05, yy)
ctx.lineTo(s * 0.05, yy)
}
ctx.stroke()
ctx.beginPath()
ctx.moveTo(-s * 0.09, -s * 0.24)
ctx.quadraticCurveTo(0, -s * 0.31, s * 0.09, -s * 0.24)
ctx.lineTo(s * 0.08, -s * 0.36)
ctx.lineTo(-s * 0.08, -s * 0.36)
ctx.closePath()
ink(ctx, C.bike, lw)
ctx.beginPath()
ctx.rect(-s * 0.05, -s * 0.27, s * 0.1, s * 0.05)
ink(ctx, '#e8e2d6', lw)
ctx.beginPath()
ctx.ellipse(0, -s * 0.335, s * 0.045, s * 0.022, 0, 0, Math.PI * 2)
ink(ctx, '#ff3a5c', lw)
glowBlob(ctx, 0, -s * 0.335, s * 0.16, '#ff2d55', 0.95)
for (const sd of [-1, 1]) {
ctx.beginPath()
ctx.ellipse(sd * s * 0.1, -s * 0.33, s * 0.016, s * 0.012, 0, 0, Math.PI * 2)
ink(ctx, '#ffa63a', lw)
}
ctx.restore()
}
// ------------------------------------------------------------------ sitting with the letter
/** Hero sitting on the ground, knees up, holding a letter. h = standing height. */
export function heroSit(ctx: C2D, x: number, y: number, h: number, t: number, o: { facing?: number; letter?: number; fire?: number } = {}) {
const f = o.facing ?? 1
const lw = Math.max(1, h * 0.007)
const hip = { x, y: y - h * 0.07 }
const lean = 0.35
const sh = { x: hip.x + f * Math.sin(lean) * h * TORSO, y: hip.y - Math.cos(lean) * h * TORSO }
const footN = { x: x + f * h * 0.3, y: y - h * 0.012 }
const footF = { x: x + f * h * 0.26, y: y - h * 0.02 }
const legN = ik(hip, footN, h * LEG1, h * LEG2, -f)
const legF = ik(hip, footF, h * LEG1, h * LEG2, -f)
const handPt = { x: legN.j.x + f * h * 0.06, y: legN.j.y - h * 0.08 }
const armN = ik(sh, handPt, h * ARM1, h * ARM2, f)
const armF = ik(sh, { x: handPt.x - f * h * 0.02, y: handPt.y + h * 0.01 }, h * ARM1, h * ARM2, f)
const r = h * 0.14
const head = { x: sh.x + f * h * 0.07, y: sh.y - h * 0.02 - r * 0.85 }
const p: Pose = { hip, sh, head, headR: r, kneeN: legN.j, footN: legN.e, kneeF: legF.j, footF: legF.e, elbowN: armN.j, handN: armN.e, elbowF: armF.j, handF: armF.e }
contactShadow(ctx, x + f * h * 0.12, y, h * 0.26)
drawFar(ctx, p, h, f, lw)
// letter between the hands
const letter = o.letter ?? 1
const lp = { x: armN.e.x + f * h * 0.01, y: armN.e.y - h * 0.02 }
if (letter > 0) {
ctx.save()
ctx.translate(lp.x, lp.y)
ctx.rotate(-0.2 * f)
ctx.globalAlpha = clamp(letter * 1.5)
const lwid = h * 0.15
const lh = h * 0.19 * letter
ctx.beginPath()
ctx.rect(-lwid / 2, -lh, lwid, lh)
ink(ctx, '#f1e6cf', lw)
ctx.fillStyle = 'rgba(80,60,40,0.45)'
for (let k = 0; k < 5; k++) if (lh * (0.18 + k * 0.15) < lh) ctx.fillRect(-lwid * 0.38, -lh + lh * (0.18 + k * 0.15), lwid * 0.76 * (k === 4 ? 0.5 : 1), Math.max(1, h * 0.005))
ctx.restore()
}
drawNear(ctx, p, h, f, lw, { t, eyes: 'closed', wind: 0.05, tilt: 0.25 })
const fire = o.fire ?? 0
if (fire > 0) flame(ctx, lp.x, lp.y - h * 0.19 * letter, h * 0.15 * fire, t)
}
export function flame(ctx: C2D, x: number, y: number, size: number, t: number) {
glowBlob(ctx, x, y - size * 0.3, size * 3.2, '#ff8a3d', 0.55)
const layers: [string, number][] = [
['#ff4a1c', 1],
['#ff9a2e', 0.72],
['#ffe08a', 0.42],
]
for (const [c, k] of layers) {
ctx.fillStyle = c
ctx.beginPath()
const w = size * 0.45 * k
const hh = size * 1.3 * k * (0.9 + 0.15 * Math.sin(t * 17 + k * 5))
const sway = Math.sin(t * 11 + k * 3) * size * 0.12
ctx.moveTo(x - w, y)
ctx.quadraticCurveTo(x - w * 1.1, y - hh * 0.5, x + sway, y - hh)
ctx.quadraticCurveTo(x + w * 1.1, y - hh * 0.5, x + w, y)
ctx.quadraticCurveTo(x, y + w * 0.6, x - w, y)
ctx.fill()
}
ctx.fillStyle = '#ffcf7a'
for (let i = 0; i < 10; i++) {
const life = (t * (0.6 + hash(i) * 0.5) + hash(i * 3.3)) % 1
ctx.globalAlpha = 1 - life
ctx.fillRect(x + Math.sin(i * 2.1 + t * 3) * size * 0.6 * life, y - size * (0.6 + life * 2.4), Math.max(1, size * 0.05), Math.max(1, size * 0.05))
}
ctx.globalAlpha = 1
}
// ------------------------------------------------------------------ front head + portrait
export interface PortraitOpts {
t: number
eyes?: number // 0 closed .. 1 open
tear?: number
wind?: number
rim?: string
smile?: boolean
tilt?: number
hair?: FrontHair
glasses?: boolean
mustache?: boolean
hatColor?: string
}
export type FrontHair = 'curly' | 'short' | 'long' | 'bun' | 'bald' | 'cap' | 'scarf' | 'chef'
/** front-view hair / headwear for other characters */
function frontHair(ctx: C2D, cx: number, cy: number, r: number, o: PortraitOpts, lw: number, layer: 'back' | 'front') {
const st = o.hair ?? 'curly'
const hc = o.hatColor ?? '#c4142f'
if (layer === 'back') {
if (st === 'long') {
ctx.beginPath()
ctx.moveTo(cx - r * 1.05, cy - r * 0.4)
ctx.quadraticCurveTo(cx - r * 1.25, cy + r * 0.9, cx - r * 0.95, cy + r * 1.5)
ctx.lineTo(cx + r * 0.95, cy + r * 1.5)
ctx.quadraticCurveTo(cx + r * 1.25, cy + r * 0.9, cx + r * 1.05, cy - r * 0.4)
ctx.closePath()
ink(ctx, C.hair, lw)
}
return
}
const capTop = (col: string) => {
ctx.beginPath()
ctx.moveTo(cx - r * 0.98, cy - r * 0.05)
ctx.quadraticCurveTo(cx - r * 1.05, cy - r * 1.12, cx, cy - r * 1.12)
ctx.quadraticCurveTo(cx + r * 1.05, cy - r * 1.12, cx + r * 0.98, cy - r * 0.05)
ctx.quadraticCurveTo(cx + r * 0.7, cy - r * 0.62, cx, cy - r * 0.6)
ctx.quadraticCurveTo(cx - r * 0.7, cy - r * 0.62, cx - r * 0.98, cy - r * 0.05)
ctx.closePath()
ink(ctx, col, lw)
}
switch (st) {
case 'short':
capTop(C.hair)
break
case 'long':
capTop(C.hair)
ctx.fillStyle = C.hair
ctx.fillRect(cx - r * 0.75, cy - r * 0.62, r * 1.5, r * 0.22)
break
case 'bun':
capTop(C.hair)
ctx.beginPath()
ctx.arc(cx, cy - r * 1.2, r * 0.36, 0, Math.PI * 2)
ink(ctx, C.hair, lw)
break
case 'bald':
for (const sd of [-1, 1]) {
ctx.beginPath()
ctx.ellipse(cx + sd * r * 0.88, cy - r * 0.1, r * 0.14, r * 0.3, 0, 0, Math.PI * 2)
ink(ctx, C.hair, lw)
}
break
case 'cap':
capTop(hc)
ctx.beginPath()
ctx.ellipse(cx, cy - r * 0.52, r * 1.05, r * 0.2, 0, 0, Math.PI * 2)
ink(ctx, hc, lw)
break
case 'scarf':
capTop(hc)
ctx.beginPath()
ctx.moveTo(cx - r * 0.98, cy - r * 0.05)
ctx.quadraticCurveTo(cx - r * 1.1, cy + r * 0.6, cx - r * 0.7, cy + r * 0.85)
ctx.lineTo(cx - r * 0.6, cy + r * 0.2)
ctx.closePath()
ink(ctx, hc, lw)
ctx.beginPath()
ctx.moveTo(cx + r * 0.98, cy - r * 0.05)
ctx.quadraticCurveTo(cx + r * 1.1, cy + r * 0.6, cx + r * 0.7, cy + r * 0.85)
ctx.lineTo(cx + r * 0.6, cy + r * 0.2)
ctx.closePath()
ink(ctx, hc, lw)
break
case 'chef':
capTop('#f4f2ee')
ctx.beginPath()
ctx.moveTo(cx - r * 0.8, cy - r * 0.8)
ctx.lineTo(cx - r * 0.75, cy - r * 1.9)
ctx.quadraticCurveTo(cx, cy - r * 2.3, cx + r * 0.75, cy - r * 1.9)
ctx.lineTo(cx + r * 0.8, cy - r * 0.8)
ctx.closePath()
ink(ctx, '#f4f2ee', lw)
break
}
}
/** Front-facing head. (cx,cy) = face centre, r = face radius. */
export function frontHead(ctx: C2D, cx: number, cy: number, r: number, o: PortraitOpts) {
const t = o.t
const lw = Math.max(1, r * 0.035)
ctx.save()
ctx.translate(cx, cy)
ctx.rotate(o.tilt ?? 0)
ctx.translate(-cx, -cy)
const curly = (o.hair ?? 'curly') === 'curly'
// back hair volume
if (curly) {
ctx.fillStyle = C.line
ctx.beginPath()
ctx.ellipse(cx, cy - r * 0.15, r * 1.34, r * 1.22, 0, 0, Math.PI * 2)
ctx.fill()
ctx.fillStyle = C.hair
ctx.beginPath()
ctx.ellipse(cx, cy - r * 0.15, r * 1.3, r * 1.18, 0, 0, Math.PI * 2)
ctx.fill()
} else frontHair(ctx, cx, cy, r, o, lw, 'back')
for (const sd of [-1, 1]) {
ctx.beginPath()
ctx.ellipse(cx + sd * r * 0.95, cy + r * 0.12, r * 0.15, r * 0.24, 0, 0, Math.PI * 2)
ink(ctx, C.skinShade, lw)
}
// face (square-ish jaw)
ctx.beginPath()
ctx.moveTo(cx - r * 0.94, cy - r * 0.2)
ctx.lineTo(cx - r * 0.9, cy + r * 0.5)
ctx.quadraticCurveTo(cx - r * 0.6, cy + r * 0.95, cx, cy + r * 1.0)
ctx.quadraticCurveTo(cx + r * 0.6, cy + r * 0.95, cx + r * 0.9, cy + r * 0.5)
ctx.lineTo(cx + r * 0.94, cy - r * 0.2)
ctx.quadraticCurveTo(cx, cy - r * 1.05, cx - r * 0.94, cy - r * 0.2)
ctx.closePath()
ink(ctx, C.skin, lw)
ctx.fillStyle = rgba(C.skinShade, 0.35)
ctx.beginPath()
ctx.ellipse(cx - r * 0.6, cy + r * 0.5, r * 0.3, r * 0.35, 0.3, 0, Math.PI * 2)
ctx.fill()
ctx.fillStyle = rgba(C.blush, 0.16)
ctx.beginPath()
ctx.ellipse(cx - r * 0.5, cy + r * 0.35, r * 0.2, r * 0.1, 0, 0, Math.PI * 2)
ctx.ellipse(cx + r * 0.5, cy + r * 0.35, r * 0.2, r * 0.1, 0, 0, Math.PI * 2)
ctx.fill()
// eyes + thick brows
const open = o.eyes ?? 0
ctx.strokeStyle = '#21160f'
ctx.fillStyle = '#21160f'
ctx.lineCap = 'round'
ctx.lineWidth = Math.max(1, r * 0.06)
for (const sd of [-1, 1]) {
const ex = cx + sd * r * 0.38
const ey = cy + r * 0.08
ctx.beginPath()
if (open < 0.3) {
ctx.arc(ex, ey - r * 0.06, r * 0.17, Math.PI * 0.15, Math.PI * 0.85)
ctx.stroke()
} else {
ctx.ellipse(ex, ey, r * 0.1, r * 0.13 * open, 0, 0, Math.PI * 2)
ctx.fill()
ctx.fillStyle = '#ffffff'
ctx.beginPath()
ctx.arc(ex + r * 0.035, ey - r * 0.04, r * 0.03, 0, Math.PI * 2)
ctx.fill()
ctx.fillStyle = '#21160f'
}
ctx.save()
ctx.lineWidth = Math.max(1.5, r * 0.1)
ctx.beginPath()
ctx.moveTo(ex - sd * r * 0.18, ey - r * 0.3)
ctx.lineTo(ex + sd * r * 0.17, ey - r * 0.25)
ctx.stroke()
ctx.restore()
}
// nose + mouth
ctx.strokeStyle = rgba(C.skinShade, 0.95)
ctx.lineWidth = Math.max(1, r * 0.05)
ctx.beginPath()
ctx.moveTo(cx + r * 0.02, cy + r * 0.25)
ctx.lineTo(cx - r * 0.05, cy + r * 0.42)
ctx.lineTo(cx + r * 0.05, cy + r * 0.44)
ctx.stroke()
ctx.strokeStyle = '#6a3530'
ctx.beginPath()
if (o.smile) ctx.arc(cx, cy + r * 0.56, r * 0.14, 0.25, Math.PI - 0.25)
else {
ctx.moveTo(cx - r * 0.13, cy + r * 0.66)
ctx.quadraticCurveTo(cx, cy + r * 0.6, cx + r * 0.13, cy + r * 0.66)
}
ctx.stroke()
const tear = o.tear ?? 0
if (tear > 0) {
const ty = cy + r * 0.2 + tear * r * 0.55
ctx.fillStyle = 'rgba(190,230,255,0.9)'
ctx.beginPath()
ctx.ellipse(cx - r * 0.42, ty, r * 0.05, r * 0.08, 0, 0, Math.PI * 2)
ctx.fill()
ctx.strokeStyle = 'rgba(190,230,255,0.45)'
ctx.lineWidth = Math.max(1, r * 0.03)
ctx.beginPath()
ctx.moveTo(cx - r * 0.42, cy + r * 0.18)
ctx.lineTo(cx - r * 0.42, ty)
ctx.stroke()
}
if (o.glasses) {
ctx.strokeStyle = '#1a1a1e'
ctx.lineWidth = Math.max(1, r * 0.05)
ctx.beginPath()
ctx.arc(cx - r * 0.38, cy + r * 0.08, r * 0.2, 0, Math.PI * 2)
ctx.moveTo(cx + r * 0.58, cy + r * 0.08)
ctx.arc(cx + r * 0.38, cy + r * 0.08, r * 0.2, 0, Math.PI * 2)
ctx.moveTo(cx - r * 0.18, cy + r * 0.06)
ctx.lineTo(cx + r * 0.18, cy + r * 0.06)
ctx.stroke()
}
if (o.mustache) {
ctx.fillStyle = C.hair
ctx.beginPath()
ctx.ellipse(cx - r * 0.12, cy + r * 0.52, r * 0.16, r * 0.06, 0.2, 0, Math.PI * 2)
ctx.ellipse(cx + r * 0.12, cy + r * 0.52, r * 0.16, r * 0.06, -0.2, 0, Math.PI * 2)
ctx.fill()
}
if (!curly) {
frontHair(ctx, cx, cy, r, o, lw, 'front')
ctx.restore()
return
}
// curly fringe + crown
curls(ctx, cx, cy - r * 0.38, r * 1.1, 1, o.wind ?? 0, t, 'front')
const fr: { x: number; y: number; rr: number }[] = []
for (let i = 0; i < 7; i++) fr.push({ x: cx + (i - 3) * r * 0.26, y: cy - r * 0.66 + Math.abs(i - 3) * r * 0.06 + Math.sin(t * 2 + i) * r * 0.01, rr: r * (0.2 + 0.05 * hash(i * 9.1)) })
ctx.fillStyle = C.line
ctx.beginPath()
for (const p of fr) {
ctx.moveTo(p.x + p.rr + lw, p.y)
ctx.arc(p.x, p.y, p.rr + lw, 0, Math.PI * 2)
}
ctx.fill()
ctx.fillStyle = C.hair
ctx.beginPath()
for (const p of fr) {
ctx.moveTo(p.x + p.rr, p.y)
ctx.arc(p.x, p.y, p.rr, 0, Math.PI * 2)
}
ctx.fill()
ctx.strokeStyle = C.hairHi
ctx.lineWidth = Math.max(1, r * 0.05)
ctx.beginPath()
for (const p of fr) {
ctx.moveTo(p.x + p.rr * 0.6 * Math.cos(-2.6), p.y + p.rr * 0.6 * Math.sin(-2.6))
ctx.arc(p.x, p.y, p.rr * 0.6, -2.6, -0.6)
}
ctx.stroke()
if (o.rim) {
ctx.strokeStyle = o.rim
ctx.lineWidth = Math.max(1, r * 0.05)
ctx.beginPath()
ctx.arc(cx, cy - r * 0.2, r * 1.45, Math.PI * 1.08, Math.PI * 1.55)
ctx.stroke()
}
ctx.restore()
}
/** Front-facing bust. (cx,cy) = face centre, size = face radius. */
export function heroPortrait(ctx: C2D, cx: number, cy: number, size: number, o: PortraitOpts) {
const r = size
const lw = Math.max(1, r * 0.035)
ctx.beginPath()
ctx.moveTo(cx - r * 2.5, cy + r * 3.3)
ctx.quadraticCurveTo(cx - r * 2.4, cy + r * 1.5, cx - r * 0.55, cy + r * 1.28)
ctx.lineTo(cx + r * 0.55, cy + r * 1.28)
ctx.quadraticCurveTo(cx + r * 2.4, cy + r * 1.5, cx + r * 2.5, cy + r * 3.3)
ctx.closePath()
ink(ctx, C.sweater, lw)
ctx.fillStyle = C.sweaterShade
ctx.beginPath()
ctx.moveTo(cx - r * 2.5, cy + r * 3.3)
ctx.quadraticCurveTo(cx - r * 2.4, cy + r * 1.5, cx - r * 1.3, cy + r * 1.34)
ctx.quadraticCurveTo(cx - r * 1.7, cy + r * 2.2, cx - r * 1.6, cy + r * 3.3)
ctx.closePath()
ctx.fill()
ctx.strokeStyle = rgba(C.sweaterHi, 0.35)
ctx.lineWidth = Math.max(1, r * 0.03)
ctx.beginPath()
for (let k = -3; k <= 3; k++) {
ctx.moveTo(cx + k * r * 0.45, cy + r * 1.75)
ctx.lineTo(cx + k * r * 0.5, cy + r * 3.2)
}
ctx.stroke()
ctx.beginPath()
ctx.rect(cx - r * 0.34, cy + r * 0.65, r * 0.68, r * 0.72)
ink(ctx, C.skinShade, lw)
ctx.beginPath()
ctx.ellipse(cx, cy + r * 1.34, r * 0.6, r * 0.2, 0, 0, Math.PI)
ctx.strokeStyle = C.line
ctx.lineWidth = r * 0.2
ctx.stroke()
ctx.strokeStyle = C.rib
ctx.lineWidth = r * 0.15
ctx.stroke()
frontHead(ctx, cx, cy, r, o)
}
// ------------------------------------------------------------------ front-view body (sitting)
export function frontTorso(ctx: C2D, cx: number, hipY: number, shY: number, h: number, lw: number) {
const sw = h * 0.16
const ww = h * 0.13
ctx.beginPath()
ctx.moveTo(cx - ww, hipY)
ctx.quadraticCurveTo(cx - sw * 1.05, (hipY + shY) / 2, cx - sw, shY + h * 0.02)
ctx.quadraticCurveTo(cx - sw * 0.6, shY - h * 0.02, cx, shY - h * 0.015)
ctx.quadraticCurveTo(cx + sw * 0.6, shY - h * 0.02, cx + sw, shY + h * 0.02)
ctx.quadraticCurveTo(cx + sw * 1.05, (hipY + shY) / 2, cx + ww, hipY)
ctx.closePath()
ink(ctx, C.sweater, lw)
ctx.fillStyle = rgba(C.sweaterShade, 0.85)
ctx.beginPath()
ctx.moveTo(cx - ww, hipY)
ctx.quadraticCurveTo(cx - sw * 1.05, (hipY + shY) / 2, cx - sw, shY + h * 0.02)
ctx.lineTo(cx - sw * 0.55, shY + h * 0.03)
ctx.quadraticCurveTo(cx - ww * 0.8, (hipY + shY) / 2, cx - ww * 0.55, hipY)
ctx.closePath()
ctx.fill()
ctx.strokeStyle = rgba(C.sweaterHi, 0.3)
ctx.lineWidth = Math.max(1, h * 0.004)
ctx.beginPath()
for (let k = -2; k <= 2; k++) {
ctx.moveTo(cx + k * h * 0.05, shY + h * 0.05)
ctx.lineTo(cx + k * h * 0.045, hipY - h * 0.03)
}
ctx.stroke()
capsule(ctx, { x: cx - ww, y: hipY - h * 0.01 }, { x: cx + ww, y: hipY - h * 0.01 }, h * 0.018, h * 0.018, C.rib, lw)
// crew collar + neck
capsule(ctx, { x: cx, y: shY }, { x: cx, y: shY - h * 0.05 }, h * 0.034, h * 0.032, C.skinShade, lw)
ctx.beginPath()
ctx.ellipse(cx, shY + h * 0.005, h * 0.05, h * 0.02, 0, 0, Math.PI)
ctx.strokeStyle = C.rib
ctx.lineWidth = h * 0.016
ctx.stroke()
}
function frontShoe(ctx: C2D, p: V, h: number, lw: number) {
ctx.beginPath()
ctx.ellipse(p.x, p.y - h * 0.018, h * 0.045, h * 0.03, 0, 0, Math.PI * 2)
ink(ctx, C.shoe, lw)
ctx.fillStyle = C.sole
ctx.fillRect(p.x - h * 0.045, p.y - h * 0.008, h * 0.09, h * 0.01)
}
/**
* Hero sitting side-saddle on his parked bike, body turned to the camera.
* (x,y) = bike ground point, s = bike scale.
*/
export function heroSideSit(ctx: C2D, x: number, y: number, s: number, o: { facing?: number; t?: number; light?: number; beam?: boolean; look?: number; rim?: string } = {}) {
const f = o.facing ?? 1
const t = o.t ?? 0
const h = HERO_H * s
const lw = Math.max(1, h * 0.007)
const A = bikeAnchors(x, y, s, f)
bike(ctx, x, y, s, { facing: f, light: o.light, beam: o.beam, parked: true })
const cx = A.seat.x + f * s * 0.04
const hipY = A.seat.y - h * 0.02
const breathe = Math.sin(t * 1.6) * h * 0.004
const shY = hipY - h * TORSO + breathe
// legs dangle on the near side, feet resting at foot-peg height
const footY = A.peg.y + s * 0.02
const swing = Math.sin(t * 1.3) * h * 0.012
const hipL = { x: cx - h * 0.07, y: hipY }
const hipR = { x: cx + h * 0.07, y: hipY }
const kneeL = { x: cx - h * 0.09, y: hipY + h * 0.06 }
const kneeR = { x: cx + h * 0.1, y: hipY + h * 0.06 }
const footL = { x: cx - h * 0.1 + swing, y: footY }
const footR = { x: cx + h * 0.12, y: footY - h * 0.01 }
frontTorso(ctx, cx, hipY, shY, h, lw)
for (const [hp, kn, ft] of [
[hipL, kneeL, footL],
[hipR, kneeR, footR],
] as [V, V, V][]) {
capsule(ctx, hp, kn, h * 0.062, h * 0.056, C.pants, lw)
capsule(ctx, kn, ft, h * 0.048, h * 0.04, C.pants, lw)
frontShoe(ctx, ft, h, lw)
}
// arms resting on the knees, hands loosely together
const hands = { x: cx + h * 0.005, y: kneeL.y - h * 0.02 }
for (const sd of [-1, 1]) {
const shp = { x: cx + sd * h * 0.15, y: shY + h * 0.03 }
const a = ik(shp, { x: hands.x + sd * h * 0.03, y: hands.y }, h * ARM1, h * ARM2, sd)
capsule(ctx, shp, a.j, h * 0.04, h * 0.035, sd < 0 ? C.sweaterShade : C.sweater, lw)
capsule(ctx, a.j, a.e, h * 0.035, h * 0.031, sd < 0 ? C.sweaterShade : C.sweater, lw)
circle(ctx, a.e, h * 0.03, C.skin, lw)
}
const r = h * 0.14
frontHead(ctx, cx, shY - h * 0.05 - r * 0.85, r, { t, eyes: 0.8, tilt: (o.look ?? 0) * 0.15, rim: o.rim, wind: 0.1 })
}
// ------------------------------------------------------------------ sitting on the ground with a newspaper (front view)
export interface PaperState {
/** 0..1 left hand bringing the lighter to the corner */
lighter?: number
/** lighter flame visible */
lit?: boolean
/** 0..1 burn progress (from the bottom-left corner) */
burn?: number
/** 0 held … 1 lying on the ground */
drop?: number
}
function paperSheet(ctx: C2D, w: number, hh: number, burn: number, t: number) {
// local: (0,0) top-left, (w,hh) bottom-right
const lw = Math.max(1, w * 0.008)
ctx.save()
// unburned region: py < px + 1 - 2p (normalised)
if (burn > 0) {
const p = burn
ctx.beginPath()
ctx.moveTo(-0.5 * w, (0.5 - 2 * p) * hh)
ctx.lineTo(1.5 * w, (2.5 - 2 * p) * hh)
ctx.lineTo(1.5 * w, -1 * hh)
ctx.lineTo(-0.5 * w, -1 * hh)
ctx.closePath()
ctx.clip()
}
ctx.beginPath()
ctx.rect(0, 0, w, hh)
ink(ctx, '#e9e3d3', lw)
// fold line + print
ctx.strokeStyle = 'rgba(90,80,60,0.35)'
ctx.lineWidth = lw
ctx.beginPath()
ctx.moveTo(w / 2, 0)
ctx.lineTo(w / 2, hh)
ctx.stroke()
ctx.fillStyle = '#1d1b18'
ctx.font = `${hh * 0.16}px "MV Black", sans-serif`
ctx.textBaseline = 'top'
ctx.fillText('黑街晚报', w * 0.06, hh * 0.05)
ctx.fillRect(w * 0.06, hh * 0.25, w * 0.38, hh * 0.012)
ctx.fillStyle = 'rgba(40,36,30,0.55)'
for (let c = 0; c < 2; c++)
for (let k = 0; k < 9; k++) ctx.fillRect(w * (0.06 + c * 0.2), hh * (0.31 + k * 0.07), w * (0.16 - (k === 8 ? 0.06 : 0)), Math.max(1, hh * 0.022))
ctx.fillStyle = 'rgba(40,36,30,0.75)'
ctx.fillRect(w * 0.55, hh * 0.08, w * 0.38, hh * 0.4)
ctx.fillStyle = 'rgba(200,190,170,0.6)'
ctx.beginPath()
ctx.arc(w * 0.74, hh * 0.3, hh * 0.1, 0, Math.PI * 2)
ctx.fill()
ctx.fillStyle = 'rgba(40,36,30,0.55)'
for (let k = 0; k < 5; k++) ctx.fillRect(w * 0.55, hh * (0.56 + k * 0.08), w * 0.38, Math.max(1, hh * 0.022))
ctx.restore()
if (burn > 0 && burn < 1) {
// charred band + flames along the burn front
const p = burn
ctx.save()
ctx.beginPath()
ctx.rect(0, 0, w, hh)
ctx.clip()
ctx.strokeStyle = 'rgba(30,18,8,0.9)'
ctx.lineWidth = hh * 0.06
ctx.beginPath()
ctx.moveTo(-0.5 * w, (0.5 - 2 * p) * hh - hh * 0.03)
ctx.lineTo(1.5 * w, (2.5 - 2 * p) * hh - hh * 0.03)
ctx.stroke()
ctx.strokeStyle = 'rgba(255,140,40,0.9)'
ctx.lineWidth = hh * 0.02
ctx.stroke()
ctx.restore()
for (let k = 0; k <= 8; k++) {
const px = k / 8
const py = px + 1 - 2 * p
if (py < 0 || py > 1) continue
flame(ctx, px * w, py * hh, hh * (0.12 + 0.08 * hash(k * 3.1 + Math.floor(t * 6))), t + k)
}
}
}
/** Hero sits on the ground facing camera, knees up, a newspaper in front of his face. h = standing height. */
export function heroSitPaper(ctx: C2D, x: number, y: number, h: number, t: number, st: PaperState = {}) {
const lw = Math.max(1, h * 0.007)
const hipY = y - h * 0.07
const shY = hipY - h * TORSO
const r = h * 0.14
contactShadow(ctx, x, y, h * 0.28)
// torso + head (behind the paper)
frontTorso(ctx, x, hipY, shY, h, lw)
const headY = shY - h * 0.05 - r * 0.85
const reveal = clamp(((st.burn ?? 0) - 0.25) / 0.3) + (st.drop ?? 0)
frontHead(ctx, x, headY, r, { t, eyes: reveal > 0.5 ? 0.9 : 0, wind: 0.05, tilt: -0.05 })
// knees up (in front of the torso)
for (const sd of [-1, 1]) {
const hp = { x: x + sd * h * 0.07, y: hipY }
const kn = { x: x + sd * h * 0.12, y: y - h * 0.3 }
const ft = { x: x + sd * h * 0.11, y }
capsule(ctx, hp, kn, h * 0.06, h * 0.05, sd < 0 ? C.pantsShade : C.pants, lw)
capsule(ctx, ft, kn, h * 0.042, h * 0.048, sd < 0 ? C.pantsShade : C.pants, lw)
frontShoe(ctx, ft, h, lw)
}
// newspaper geometry
const pw = h * 0.46
const ph = h * 0.32
const drop = st.drop ?? 0
const burn = st.burn ?? 0
const held = { x: x - pw / 2, y: headY - ph * 0.45 }
const ground = { x: x - pw * 0.15, y: y + h * 0.04 }
const px0 = held.x + (ground.x - held.x) * drop
const py0 = held.y + (ground.y - held.y) * drop * drop
const sy = 1 - drop * 0.72 // lying flat → foreshortened
// hands: right hand holds the top-right edge; left hand holds the left edge or the lighter
const rightHand = drop < 0.15 ? { x: px0 + pw, y: py0 + ph * 0.35 * sy } : { x: x + h * 0.14, y: y - h * 0.34 }
const leftHold = { x: px0, y: py0 + ph * 0.5 * sy }
const lighterPos = { x: px0 + pw * 0.02, y: py0 + ph * 1.04 }
const restL = { x: x - h * 0.14, y: y - h * 0.34 }
const lk = st.lighter ?? 0
let leftHand: V
if (burn > 0.3 || drop > 0) leftHand = restL
else if (lk <= 0) leftHand = leftHold
else if (lk < 0.5) leftHand = lerpV(leftHold, { x: x - h * 0.2, y: y - h * 0.25 }, lk * 2) // reach into the pocket
else leftHand = lerpV({ x: x - h * 0.2, y: y - h * 0.25 }, lighterPos, (lk - 0.5) * 2)
// arms (drawn before the paper when holding it up)
const arms = () => {
for (const [sd, hand] of [
[-1, leftHand],
[1, rightHand],
] as [number, V][]) {
const shp = { x: x + sd * h * 0.15, y: shY + h * 0.03 }
const a = ik(shp, hand, h * ARM1, h * ARM2, sd)
capsule(ctx, shp, a.j, h * 0.04, h * 0.035, sd < 0 ? C.sweaterShade : C.sweater, lw)
capsule(ctx, a.j, a.e, h * 0.035, h * 0.031, sd < 0 ? C.sweaterShade : C.sweater, lw)
circle(ctx, a.e, h * 0.03, C.skin, lw)
}
}
if (burn < 1) {
ctx.save()
ctx.translate(px0, py0)
ctx.scale(1, sy)
ctx.rotate(-0.04 + drop * 0.25)
paperSheet(ctx, pw, ph, burn, t)
ctx.restore()
} else {
// ashes + embers on the ground
ctx.fillStyle = 'rgba(30,26,22,0.85)'
ctx.beginPath()
ctx.ellipse(ground.x + pw * 0.45, ground.y + ph * 0.12, pw * 0.4, ph * 0.08, 0, 0, Math.PI * 2)
ctx.fill()
ctx.fillStyle = '#ff8a3d'
for (let k = 0; k < 14; k++) {
ctx.globalAlpha = 0.4 + 0.6 * Math.abs(Math.sin(t * 3 + k))
ctx.fillRect(ground.x + pw * (0.1 + 0.7 * hash(k)), ground.y + ph * (0.06 + 0.12 * hash(k * 2)), h * 0.008, h * 0.008)
}
ctx.globalAlpha = 1
}
arms()
// the lighter
if (lk > 0.5 && burn <= 0.3 && drop === 0) {
ctx.save()
ctx.translate(leftHand.x, leftHand.y)
ctx.beginPath()
ctx.rect(-h * 0.012, -h * 0.05, h * 0.024, h * 0.045)
ink(ctx, '#c4142f', lw)
ctx.beginPath()
ctx.rect(-h * 0.012, -h * 0.062, h * 0.024, h * 0.014)
ink(ctx, C.chrome, lw)
ctx.restore()
if (st.lit) flame(ctx, leftHand.x, leftHand.y - h * 0.062, h * 0.03, t)
}
// smoke / ash flakes drifting up while burning
if (burn > 0) {
for (let k = 0; k < 16; k++) {
const life = fract(t * (0.3 + hash(k) * 0.3) + hash(k * 7))
ctx.fillStyle = k % 3 ? `rgba(60,55,50,${0.5 * (1 - life)})` : `rgba(255,150,60,${0.8 * (1 - life)})`
ctx.fillRect(px0 + pw * hash(k * 3.3) + Math.sin(t + k) * h * 0.03, py0 - life * h * 0.5, h * 0.012, h * 0.008)
}
}
}
// ------------------------------------------------------------------ other people
/** side-view hair / headwear (local: facing +x, head centre 0,0, radius r) */
function sideHair(ctx: C2D, r: number, style: HairStyle, lw: number, t: number) {
const cap = () => {
ctx.beginPath()
ctx.moveTo(r * 0.62, -r * 0.5)
ctx.quadraticCurveTo(r * 0.3, -r * 1.12, -r * 0.4, -r * 0.95)
ctx.quadraticCurveTo(-r * 0.95, -r * 0.6, -r * 0.82, r * 0.1)
ctx.quadraticCurveTo(-r * 0.6, r * 0.45, -r * 0.35, r * 0.4)
ctx.quadraticCurveTo(-r * 0.3, -r * 0.1, r * 0.1, -r * 0.48)
ctx.closePath()
ink(ctx, C.hair, lw)
}
if (style === 'bald') {
ctx.beginPath()
ctx.ellipse(-r * 0.45, r * 0.05, r * 0.25, r * 0.3, 0, 0, Math.PI * 2)
ink(ctx, C.hair, lw)
return
}
if (style === 'long') {
ctx.beginPath()
ctx.moveTo(-r * 0.2, -r * 0.6)
ctx.quadraticCurveTo(-r * 1.15, -r * 0.2, -r * 0.95, r * 1.55)
ctx.lineTo(-r * 0.25, r * 1.45 + Math.sin(t * 2) * r * 0.05)
ctx.quadraticCurveTo(-r * 0.35, r * 0.6, -r * 0.2, r * 0.2)
ctx.closePath()
ink(ctx, C.hair, lw)
}
if (style === 'ponytail') {
ctx.beginPath()
ctx.moveTo(-r * 0.75, -r * 0.35)
ctx.quadraticCurveTo(-r * 1.6, -r * 0.1 + Math.sin(t * 6) * r * 0.1, -r * 1.25, r * 0.95)
ctx.quadraticCurveTo(-r * 1.0, r * 0.2, -r * 0.7, -r * 0.05)
ctx.closePath()
ink(ctx, C.hair, lw)
}
if (style === 'bun') {
ctx.beginPath()
ctx.arc(-r * 0.75, -r * 0.75, r * 0.38, 0, Math.PI * 2)
ink(ctx, C.hair, lw)
}
cap()
if (style === 'cap') {
ctx.beginPath()
ctx.moveTo(-r * 0.85, -r * 0.2)
ctx.quadraticCurveTo(-r * 0.7, -r * 1.2, r * 0.45, -r * 0.85)
ctx.lineTo(r * 1.25, -r * 0.62)
ctx.lineTo(r * 1.2, -r * 0.5)
ctx.lineTo(-r * 0.85, -r * 0.2)
ctx.closePath()
ink(ctx, C.rib, lw)
}
if (style === 'hat') {
ctx.beginPath()
ctx.moveTo(-r * 1.3, -r * 0.5)
ctx.lineTo(r * 1.25, -r * 0.62)
ctx.lineTo(r * 0.6, -r * 0.82)
ctx.quadraticCurveTo(0, -r * 1.5, -r * 0.7, -r * 0.75)
ctx.closePath()
ink(ctx, C.rib, lw)
}
}
export interface PersonStyle {
palette: Partial<typeof HERO>
hair: HairStyle
skirt?: string
/** colour of the legs under a skirt (skin or tights) */
legs?: string
shortSleeves?: boolean
scale?: number
stoop?: number
carry?: 'none' | 'skewer' | 'cup' | 'phone' | 'bag' | 'cane'
}
/** a passer-by: same rig, different body, clothes, hair and props */
export function personWalk(ctx: C2D, x: number, y: number, h0: number, phase: number, st: PersonStyle, t: number, facing = 1) {
withPalette(st.palette, () => {
const h = h0 * (st.scale ?? 1)
const f = facing
const lw = Math.max(1, h * 0.007)
const slow = st.stoop ? 0.6 : 1
const p = walkPose(x, y, h, phase * slow, { facing: f })
if (st.stoop) {
const k = st.stoop
p.sh = { x: p.sh.x + f * h * 0.08 * k, y: p.sh.y + h * 0.04 * k }
p.head = { x: p.head.x + f * h * 0.11 * k, y: p.head.y + h * 0.06 * k }
}
// props in the near hand
const holdUp = st.carry === 'skewer' || st.carry === 'cup' || st.carry === 'phone'
if (holdUp) {
const target = { x: p.sh.x + f * h * 0.12, y: p.sh.y + h * 0.04 }
const a = ik(p.sh, target, h * ARM1, h * ARM2, f)
p.elbowN = a.j
p.handN = a.e
}
if (st.carry === 'cane') {
const target = { x: p.sh.x + f * h * 0.12, y: p.sh.y + h * 0.27 }
const a = ik(p.sh, target, h * ARM1, h * ARM2, f)
p.elbowN = a.j
p.handN = a.e
}
contactShadow(ctx, x, y, h * 0.2)
const arm = (near: boolean) => {
const e = near ? p.elbowN : p.elbowF
const hd = near ? p.handN : p.handF
const col = near ? C.sweater : C.sweaterShade
if (st.shortSleeves) {
const mid = { x: p.sh.x + (e.x - p.sh.x) * 0.6, y: p.sh.y + (e.y - p.sh.y) * 0.6 }
capsule(ctx, p.sh, mid, h * 0.045, h * 0.042, col, lw)
capsule(ctx, mid, e, h * 0.03, h * 0.028, C.skin, lw)
capsule(ctx, e, hd, h * 0.028, h * 0.025, C.skin, lw)
circle(ctx, hd, h * 0.028, C.skin, lw)
} else armPiece(ctx, p.sh, e, hd, h, near, lw)
}
if (st.skirt) {
// legs show only below the hem; the skirt covers the thighs
const legCol = st.legs ?? C.skin
const shin = (kn: V, ft: V, near: boolean) => {
capsule(ctx, kn, ft, h * 0.036, h * 0.03, near ? legCol : rgba(legCol, 0.85), lw)
shoe(ctx, ft, h, f, lw)
}
shin(p.kneeF, p.footF, false)
arm(false)
const hemY = Math.max(p.kneeN.y, p.kneeF.y) + h * 0.015
const xs = [p.kneeN.x, p.kneeF.x]
const hemL = Math.min(...xs) - h * 0.07
const hemR = Math.max(...xs) + h * 0.07
const sway = Math.sin(phase * Math.PI * 4) * h * 0.012
ctx.beginPath()
ctx.moveTo(p.hip.x - h * 0.085, p.hip.y - h * 0.05)
ctx.lineTo(p.hip.x + h * 0.085, p.hip.y - h * 0.05)
ctx.quadraticCurveTo(hemR + sway, (p.hip.y + hemY) / 2, hemR + sway, hemY)
ctx.lineTo(hemL + sway, hemY + h * 0.008)
ctx.quadraticCurveTo(hemL + sway, (p.hip.y + hemY) / 2, p.hip.x - h * 0.085, p.hip.y - h * 0.05)
ctx.closePath()
ink(ctx, st.skirt, lw)
ctx.strokeStyle = rgba(C.line, 0.3)
ctx.beginPath()
ctx.moveTo(p.hip.x, p.hip.y)
ctx.lineTo(p.hip.x + sway, hemY)
ctx.stroke()
// torso, head, near shin, near arm
capsule(ctx, p.sh, { x: p.head.x - f * p.headR * 0.1, y: p.head.y + p.headR * 0.6 }, h * 0.03, h * 0.028, C.skinShade, lw)
torso(ctx, p.hip, p.sh, h, f, lw)
shin(p.kneeN, p.footN, true)
heroHead(ctx, p.head.x, p.head.y, p.headR, f, { t, eyes: 'open', hair: st.hair, wind: 0 })
arm(true)
} else {
legPiece(ctx, p.hip, p.kneeF, p.footF, h, f, false, lw)
arm(false)
capsule(ctx, p.sh, { x: p.head.x - f * p.headR * 0.1, y: p.head.y + p.headR * 0.6 }, h * 0.032, h * 0.03, C.skinShade, lw)
torso(ctx, p.hip, p.sh, h, f, lw)
legPiece(ctx, p.hip, p.kneeN, p.footN, h, f, true, lw)
heroHead(ctx, p.head.x, p.head.y, p.headR, f, { t, eyes: 'open', hair: st.hair, wind: 0 })
arm(true)
}
const hand = p.handN
if (st.carry === 'skewer') {
ctx.strokeStyle = '#d8b07a'
ctx.lineWidth = Math.max(1, h * 0.006)
ctx.beginPath()
ctx.moveTo(hand.x, hand.y)
ctx.lineTo(hand.x + f * h * 0.02, hand.y - h * 0.16)
ctx.stroke()
ctx.fillStyle = '#8a3a1a'
for (let k = 0; k < 4; k++) ctx.fillRect(hand.x + f * h * 0.004 * k - h * 0.012, hand.y - h * (0.06 + k * 0.026), h * 0.024, h * 0.02)
} else if (st.carry === 'cup') {
ctx.beginPath()
ctx.moveTo(hand.x - h * 0.022, hand.y - h * 0.07)
ctx.lineTo(hand.x + h * 0.022, hand.y - h * 0.07)
ctx.lineTo(hand.x + h * 0.017, hand.y + h * 0.01)
ctx.lineTo(hand.x - h * 0.017, hand.y + h * 0.01)
ctx.closePath()
ink(ctx, '#f0e0c8', lw)
ctx.fillStyle = '#2a1a10'
for (let k = 0; k < 4; k++) ctx.fillRect(hand.x - h * 0.012 + k * h * 0.007, hand.y - h * 0.005, h * 0.005, h * 0.005)
ctx.strokeStyle = '#ff5fa2'
ctx.lineWidth = Math.max(1, h * 0.005)
ctx.beginPath()
ctx.moveTo(hand.x, hand.y - h * 0.07)
ctx.lineTo(hand.x + f * h * 0.01, hand.y - h * 0.11)
ctx.stroke()
} else if (st.carry === 'phone') {
ctx.fillStyle = '#cfe8ff'
ctx.fillRect(hand.x - h * 0.012, hand.y - h * 0.05, h * 0.024, h * 0.045)
glowBlob(ctx, hand.x, hand.y - h * 0.03, h * 0.12, '#7fc8ff', 0.5)
} else if (st.carry === 'bag') {
ctx.beginPath()
ctx.roundRect(hand.x - h * 0.035, hand.y + h * 0.01, h * 0.07, h * 0.09, h * 0.01)
ink(ctx, '#e8e2d6', lw)
} else if (st.carry === 'cane') {
ctx.strokeStyle = '#4a2e1a'
ctx.lineWidth = Math.max(1, h * 0.01)
ctx.beginPath()
ctx.moveTo(hand.x, hand.y)
ctx.lineTo(hand.x + f * h * 0.04, y)
ctx.stroke()
}
})
}
/** standing with his back against a tree trunk, arms folded, one ankle crossed, looking up. (x,y) feet/trunk contact */
export function heroLean(ctx: C2D, x: number, y: number, h: number, t: number, o: { facing?: number; rim?: string } = {}) {
const f = o.facing ?? 1
const lw = Math.max(1, h * 0.007)
const breathe = Math.sin(t * 1.4) * h * 0.003
const hip = { x: x + f * h * 0.1, y: y - h * 0.39 }
const lean = -0.2 // back against the trunk
const sh = { x: hip.x + f * Math.sin(lean) * h * TORSO, y: hip.y - Math.cos(lean) * h * TORSO + breathe }
const footN = { x: x + f * h * 0.3, y }
const footF = { x: x + f * h * 0.24, y: y - h * 0.005 }
const legN = ik(hip, footN, h * LEG1, h * LEG2, -f)
const legF = ik(hip, footF, h * LEG1, h * LEG2, -f)
// folded arms: both hands meet in front of the chest
const chest = { x: sh.x + f * h * 0.08, y: sh.y + h * 0.1 }
const armN = ik(sh, { x: chest.x + f * h * 0.03, y: chest.y }, h * ARM1, h * ARM2, f)
const armF = ik(sh, { x: chest.x - f * h * 0.01, y: chest.y - h * 0.02 }, h * ARM1, h * ARM2, f)
const r = h * 0.14
const head = { x: sh.x + f * h * 0.02, y: sh.y - h * 0.035 - r * 0.95 }
const p: Pose = { hip, sh, head, headR: r, kneeN: legN.j, footN: legN.e, kneeF: legF.j, footF: legF.e, elbowN: armN.j, handN: armN.e, elbowF: armF.j, handF: armF.e }
contactShadow(ctx, x + f * h * 0.18, y, h * 0.2)
drawFar(ctx, p, h, f, lw)
drawNear(ctx, p, h, f, lw, { t, eyes: 'open', smile: true, wind: 0.15, tilt: -0.18, rim: o.rim })
}
export interface VendorStyle {
palette: Partial<typeof HERO>
hair: FrontHair
hatColor?: string
apron?: string
glasses?: boolean
mustache?: boolean
smile?: boolean
scale?: number
}
/** a stall-keeper facing the camera, working behind the counter. (x, counterY) = centre on the counter top */
export function vendorFront(ctx: C2D, x: number, counterY: number, h0: number, st: VendorStyle, t: number, seed = 0) {
withPalette(st.palette, () => {
const h = h0 * (st.scale ?? 1)
const lw = Math.max(1, h * 0.007)
const hipY = counterY + h * 0.08
const shY = hipY - h * TORSO
frontTorso(ctx, x, hipY, shY, h, lw)
if (st.apron) {
ctx.beginPath()
ctx.moveTo(x - h * 0.1, shY + h * 0.08)
ctx.lineTo(x + h * 0.1, shY + h * 0.08)
ctx.lineTo(x + h * 0.12, hipY + h * 0.05)
ctx.lineTo(x - h * 0.12, hipY + h * 0.05)
ctx.closePath()
ink(ctx, st.apron, lw)
ctx.strokeStyle = st.apron
ctx.lineWidth = h * 0.012
ctx.beginPath()
ctx.moveTo(x - h * 0.08, shY + h * 0.08)
ctx.lineTo(x - h * 0.04, shY - h * 0.01)
ctx.moveTo(x + h * 0.08, shY + h * 0.08)
ctx.lineTo(x + h * 0.04, shY - h * 0.01)
ctx.stroke()
}
// working arms: elbows out, hands busy on the counter
for (const sd of [-1, 1]) {
const work = Math.sin(t * (3 + (seed % 3)) + sd + seed) * h * 0.025
const shp = { x: x + sd * h * 0.15, y: shY + h * 0.03 }
const hand = { x: x + sd * h * 0.09, y: counterY - h * 0.01 + (sd > 0 ? work : -work * 0.5) }
const a = ik(shp, hand, h * ARM1, h * ARM2, sd)
capsule(ctx, shp, a.j, h * 0.04, h * 0.035, sd < 0 ? C.sweaterShade : C.sweater, lw)
capsule(ctx, a.j, a.e, h * 0.035, h * 0.031, C.skin, lw)
circle(ctx, a.e, h * 0.03, C.skin, lw)
}
const r = h * 0.14
frontHead(ctx, x, shY - h * 0.05 - r * 0.85, r, { t, eyes: 1, smile: st.smile, hair: st.hair, hatColor: st.hatColor, glasses: st.glasses, mustache: st.mustache, tilt: Math.sin(t * 0.7 + seed) * 0.05 })
})
}
|