Files

49 lines
8.0 KiB
JavaScript

(()=>{
const rng=seed=>()=>{seed=(seed*1664525+1013904223)>>>0;return seed/4294967296};
const T="#9CCEC8",TD="#84CAC8",P="#F69971",W="#FFFFFF",C="#FCEACA";
const ICONS={
mail:"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 220 200\"><path d=\"M64 30 Q98 26 151 30 Q165 31 166 46 L162 176 Q162 189 148 190 L65 187 Q52 187 53 173 L55 46 Q55 33 64 30Z\" fill=\"#52B8B1\"/><path d=\"M69 44 Q107 41 151 45 L148 174 L68 172Z\" fill=\"#FFF8EC\"/><circle cx=\"91\" cy=\"70\" r=\"10\" fill=\"#52B8B1\"/><path d=\"M76 95 Q77 82 91 82 Q105 83 106 96Z\" fill=\"#52B8B1\"/><g stroke=\"#52B8B1\" stroke-width=\"7\" stroke-linecap=\"round\"><path d=\"M117 69L135 69 M117 87L134 87 M82 118L134 118 M82 141L116 141\"/></g><g transform=\"rotate(33 155 133)\"><path d=\"M147 83 Q147 77 154 77 L165 77 Q171 77 171 84 L171 161 L159 181 L147 161Z\" fill=\"#F69971\"/><path d=\"M147 93L171 93\" stroke=\"#FFF8EC\" stroke-width=\"5\"/><path d=\"M147 161L171 161L159 181Z\" fill=\"#F7E4BD\"/><path d=\"M154 172L159 181L165 172Z\" fill=\"#3E5F5C\"/><path d=\"M154 103L154 153\" stroke=\"#FFF8EC\" stroke-width=\"3\" stroke-linecap=\"round\" opacity=\".75\"/></g></svg>",
lesson:"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 220 200\"><path d=\"M48 45 Q47 34 60 34 L164 36 Q176 36 176 49 L174 137 Q174 148 162 148 L59 146 Q47 146 47 134Z\" fill=\"#52B8B1\"/><path d=\"M59 48L163 49L162 134L60 132Z\" fill=\"#FFF8EC\"/><circle cx=\"107\" cy=\"78\" r=\"15\" fill=\"#F69971\"/><path d=\"M78 122 Q79 96 106 96 Q133 96 135 123Z\" fill=\"#F69971\"/><path d=\"M31 157Q108 162 191 156L178 173Q110 182 44 172Z\" fill=\"#52B8B1\"/><path d=\"M83 159L133 159L126 166L90 165Z\" fill=\"#FFF8EC\"/><path d=\"M144 58Q137 58 137 49L139 21Q139 13 149 14L190 16Q199 17 198 26L197 50Q197 59 187 59L161 58L145 70Z\" fill=\"#F69971\"/><g fill=\"none\" stroke=\"#FFF8EC\" stroke-width=\"4\" stroke-linecap=\"round\"><path d=\"M151 28L150 45M165 29L164 45M151 37L165 37M179 34L179 45M179 26L179 27\"/></g></svg>",
group:"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 220 200\"><circle cx=\"110\" cy=\"38\" r=\"18\" fill=\"#F69971\"/>\n<path d=\"M83 91Q83 64 110 64Q137 64 137 91Z\" fill=\"#F69971\"/>\n<circle cx=\"28\" cy=\"91\" r=\"17\" fill=\"#52B8B1\"/>\n<path d=\"M5 159Q5 117 28 117Q48 117 49 159Z\" fill=\"#52B8B1\"/>\n<circle cx=\"192\" cy=\"91\" r=\"17\" fill=\"#52B8B1\"/>\n<path d=\"M171 159Q172 117 192 117Q215 117 215 159Z\" fill=\"#52B8B1\"/>\n<path d=\"M83 151L75 187M137 151L145 187\" fill=\"none\" stroke=\"#3F9C96\" stroke-width=\"8\" stroke-linecap=\"round\"/>\n<path d=\"M60 124C60 99 160 99 160 124L160 136C160 162 60 162 60 136Z\" fill=\"#84BAB5\"/>\n<ellipse cx=\"110\" cy=\"124\" rx=\"50\" ry=\"22\" fill=\"#52B8B1\"/>\n<path d=\"M81 116Q96 112 110 120Q124 112 139 116L138 135Q123 132 110 139Q97 132 82 135Z\" fill=\"#FFF8EC\"/>\n<path d=\"M110 120L110 138\" fill=\"none\" stroke=\"#F69971\" stroke-width=\"3\" stroke-linecap=\"round\"/></svg>",
calendar:"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 220 200\"><path d=\"M25 79Q66 66 109 86Q151 66 193 79L189 175Q146 161 109 181Q70 162 29 175Z\" fill=\"#52B8B1\"/><path d=\"M36 88Q70 80 103 96L103 166Q69 152 39 163Z\" fill=\"#FFF8EC\"/><path d=\"M116 96Q151 80 181 88L179 163Q147 152 116 167Z\" fill=\"#FFF8EC\"/><g fill=\"none\" stroke=\"#52B8B1\" stroke-width=\"5\" stroke-linecap=\"round\"><path d=\"M51 113Q70 108 87 117M51 131Q70 127 87 135M130 126Q148 120 166 121M130 144Q149 138 165 140\"/></g><path d=\"M115 71L139 53L157 59L183 28\" fill=\"none\" stroke=\"#F69971\" stroke-width=\"7\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/><path d=\"M164 30L184 27L184 47\" fill=\"none\" stroke=\"#F69971\" stroke-width=\"7\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>"
};
const sandRidge=(y,i,w)=>{
const silhouettes=[
'M-350 35C-120 42 90 72 230 4C352 -56 359 -126 507 -139C680 -154 827 -71 979 -62C1122 -53 1114 -212 1242 -227C1367 -244 1464 -150 1582 -175C1735 -207 1765 -320 1930 -311C2091 -302 2229 -220 2398 -248C2531 -270 2650 -343 2950 -318L2950 -154C2670 -176 2544 -102 2385 -89C2180 -70 2075 -142 1914 -146C1737 -150 1692 -39 1558 -26C1400 -11 1339 -94 1228 -63C1119 -33 1159 94 992 104C819 114 670 28 510 51C360 72 340 150 212 179C43 216 -133 175 -350 190Z',
'M-350 40C-131 14 63 112 238 43C380 -14 409 -91 539 -102C674 -114 772 -18 899 -47C1000 -70 1002 -186 1113 -206C1241 -229 1365 -151 1499 -164C1652 -179 1681 -285 1829 -304C1998 -325 2121 -220 2292 -255C2445 -285 2571 -366 2950 -325L2950 -165C2601 -202 2485 -113 2308 -97C2134 -82 1981 -168 1833 -122C1692 -77 1673 7 1511 16C1341 24 1233 -56 1139 -9C1063 29 1070 121 927 137C780 155 675 60 534 83C407 104 364 183 223 211C39 248 -138 178 -350 205Z'
];
const crest=[
'M-350 35C-120 42 90 72 230 4C352 -56 359 -126 507 -139C680 -154 827 -71 979 -62C1122 -53 1114 -212 1242 -227C1367 -244 1464 -150 1582 -175C1735 -207 1765 -320 1930 -311C2091 -302 2229 -220 2398 -248C2531 -270 2650 -343 2950 -318L2950 -296C2650 -321 2537 -245 2401 -225C2220 -198 2089 -279 1927 -286C1776 -293 1738 -183 1588 -150C1462 -123 1360 -219 1244 -202C1125 -184 1137 -25 982 -35C819 -27 675 -127 510 -112C372 -99 361 -27 241 31C93 101 -121 70 -350 61Z',
'M-350 40C-131 14 63 112 238 43C380 -14 409 -91 539 -102C674 -114 772 -18 899 -47C1000 -70 1002 -186 1113 -206C1241 -229 1365 -151 1499 -164C1652 -179 1681 -285 1829 -304C1998 -325 2121 -220 2292 -255C2445 -285 2571 -366 2950 -325L2950 -304C2574 -342 2455 -260 2295 -231C2110 -196 1997 -301 1833 -276C1696 -257 1655 -152 1501 -139C1358 -124 1241 -200 1118 -180C1014 -163 1016 -41 904 -20C764 7 673 -88 541 -75C421 -63 393 10 246 69C63 140 -132 40 -350 65Z'
];
return `<g transform="translate(0 ${y}) scale(${w/2600} 1)"><path d="${silhouettes[i%2]}" fill="#F7E4BD" opacity=".82"/><path d="${crest[i%2]}" fill="#F0D6A3" opacity=".66"/></g>`;
};
const sandGrains=(count,w,h,start,r)=>{let s='';for(let i=0;i<count;i++){const x=r()*w,y=start+r()*(h-start),rx=1.8+r()*3.9,ry=rx*(.65+r()*.6),angle=r()*180;s+=`<ellipse cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" rx="${rx.toFixed(1)}" ry="${ry.toFixed(1)}" transform="rotate(${angle.toFixed(0)} ${x.toFixed(1)} ${y.toFixed(1)})" fill="${i%3?'#E4C582':'#EED5A5'}" opacity="${(.45+r()*.3).toFixed(2)}"/>`;}return s;};
function sand(svg){
const r=rng(+svg.dataset.seed||5);let h="";
[290,790,1290].forEach((y,i)=>{h+=sandRidge(y,i,1920)});
h+=sandGrains(180,1920,1080,0,r);
svg.setAttribute("viewBox","0 0 1920 1080");svg.setAttribute("preserveAspectRatio","xMidYMid slice");svg.innerHTML=h;
}
document.querySelectorAll(".howto__bg").forEach(sand);
const jit=rng(53);
const jitter=()=>`translate(0 ${((jit()-.5)*9).toFixed(1)}) rotate(${((jit()-.5)*7).toFixed(1)} 20 100) scale(1 ${(.94+jit()*.1).toFixed(3)})`;
const BRUSH=window.brushTable({});
function brush(svg){
const word=svg.dataset.word,start=+svg.dataset.start||0;
let cx=0,h="";
[...word].forEach((ch,i)=>{
const g=BRUSH[ch];
if(g.d){const t=`translate(${cx} 0) ${jitter()}`;h+=`<g class="reveal howto__glyph" style="--d:${(start+i*.04).toFixed(2)}s"><path class="howto__shadow" d="${g.d}" transform="translate(-8 8) ${t}"/><path class="howto__ink" d="${g.d}" transform="${t}"/></g>`;}
cx+=g.w+16;
});
svg.setAttribute("viewBox",`-24 -6 ${cx-16+48} 118`);
svg.innerHTML=`<defs><filter id="howto-brush" x="-5%" y="-10%" width="110%" height="120%"><feTurbulence type="fractalNoise" baseFrequency=".09" numOctaves="2" seed="3"/><feDisplacementMap in="SourceGraphic" scale="6"/></filter></defs><g filter="url(#howto-brush)">${h}</g>`;
}
document.querySelectorAll(".howto__brush").forEach(brush);
document.querySelectorAll(".howto [data-icon]").forEach(el=>{el.outerHTML=ICONS[el.dataset.icon].replace("<svg ",'<svg class="howto__icon" aria-hidden="true" ')});
const io=new IntersectionObserver(es=>es.forEach(e=>{if(e.intersectionRatio>=.5)e.target.classList.add("howto--play");else if(e.intersectionRatio===0)e.target.classList.remove("howto--play")}),{threshold:[0,.5]});
document.querySelectorAll(".howto:not([data-stage] *)").forEach(s=>io.observe(s));
})();