103 lines
8.4 KiB
PHP
103 lines
8.4 KiB
PHP
{{-- PL0XION koin — le KOIN = un TRIANGLE qui peut prendre N'IMPORTE QUELLE FORME
|
|
(RS-7 : « les koins c'est un triangle qui peut prendre n'importe quelle forme »).
|
|
4 modes : libre (déforme le triangle au doigt) · morph (il se transforme tout
|
|
seul) · éventail (n'importe quelle forme = un éventail de koins) · instable
|
|
(le koin tremble — il faut le chill dans un kion, cf. grammaire de RS-7). Pendant
|
|
des primitives portion/wormion. 100% canvas. window.jOSApps['koin']. mount->{unmount}. --}}
|
|
<style>
|
|
.kn { position:relative; height:100%; background:#06040a; overflow:hidden; font-family:ui-sans-serif,system-ui,sans-serif; }
|
|
.kn canvas { display:block; width:100%; height:100%; touch-action:none; cursor:crosshair; }
|
|
.kn__bar { position:absolute; left:10px; top:9px; display:flex; gap:5px; flex-wrap:wrap; align-items:center; }
|
|
.kn__m { cursor:pointer; font-size:.66rem; padding:3px 9px; border-radius:7px; border:1px solid rgba(255,150,200,.32);
|
|
background:rgba(30,14,24,.7); color:rgba(255,190,220,.9); font-family:inherit; }
|
|
.kn__m.on { background:rgba(180,60,120,.55); color:#fff; border-color:rgba(255,170,210,.8); }
|
|
.kn__n { font-size:.64rem; color:rgba(255,190,220,.65); margin-left:4px; }
|
|
.kn__n input { vertical-align:middle; width:84px; }
|
|
.kn__chill { cursor:pointer; font-size:.64rem; padding:3px 9px; border-radius:7px; border:1px solid rgba(120,170,255,.4); background:rgba(20,30,60,.6); color:#bcd; font-family:inherit; }
|
|
.kn__chill.on { background:rgba(60,90,180,.6); color:#fff; }
|
|
.kn__hint { position:absolute; right:10px; bottom:9px; font-size:.62rem; color:rgba(220,180,210,.6); background:rgba(12,8,18,.6); padding:3px 8px; border-radius:7px; pointer-events:none; }
|
|
</style>
|
|
<script>
|
|
(function () {
|
|
function mount(container, ctx) {
|
|
var MODES = [['libre','△'], ['morph','✶'], ['éventail','◈'], ['instable','꩜']];
|
|
container.innerHTML = '<div class="kn"><canvas></canvas>'
|
|
+ '<div class="kn__bar">' + MODES.map(function (m, i) { return '<button class="kn__m' + (i === 0 ? ' on' : '') + '" data-m="' + m[0] + '">' + m[1] + ' ' + m[0] + '</button>'; }).join('')
|
|
+ '<span class="kn__n" data-fan style="display:none">côtés <input type="range" min="3" max="14" value="7" data-n></span>'
|
|
+ '<button class="kn__chill" data-chill style="display:none">▢ chill dans un kion</button></div>'
|
|
+ '<div class="kn__hint">libre : tire les 3 coins · le koin prend la forme que tu veux</div></div>';
|
|
var root = container.querySelector('.kn'), cv = container.querySelector('canvas'), cx = cv.getContext('2d');
|
|
var W = 0, H = 0, mode = 'libre', drag = -1, raf = 0, t = 0, chill = false, n = 7;
|
|
var pts = null; // 3 sommets du koin (mode libre/instable)
|
|
|
|
function size() { var r = root.getBoundingClientRect(), dpr = Math.min(2, devicePixelRatio || 1);
|
|
W = r.width; H = r.height; cv.width = Math.max(1, W * dpr); cv.height = Math.max(1, H * dpr); cx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
if (!pts) { var cxp = W / 2, cyp = H / 2, R = Math.min(W, H) * 0.28;
|
|
pts = [[cxp, cyp - R], [cxp + R * 0.87, cyp + R * 0.5], [cxp - R * 0.87, cyp + R * 0.5]]; } }
|
|
|
|
function tri(p, fill, stroke) {
|
|
cx.beginPath(); cx.moveTo(p[0][0], p[0][1]); cx.lineTo(p[1][0], p[1][1]); cx.lineTo(p[2][0], p[2][1]); cx.closePath();
|
|
if (fill) { cx.fillStyle = fill; cx.fill(); } if (stroke) { cx.strokeStyle = stroke; cx.lineWidth = 2; cx.stroke(); }
|
|
}
|
|
function handles(p) { for (var i = 0; i < 3; i++) { cx.beginPath(); cx.arc(p[i][0], p[i][1], 7, 0, 6.283); cx.fillStyle = '#fff'; cx.fill(); cx.strokeStyle = '#b33'; cx.lineWidth = 2; cx.stroke(); } }
|
|
|
|
function draw() {
|
|
cx.clearRect(0, 0, W, H); var X = W / 2, Y = H / 2, R = Math.min(W, H) * 0.3;
|
|
if (mode === 'libre') {
|
|
tri(pts, 'rgba(255,120,180,.35)', 'rgba(255,150,200,.95)'); handles(pts);
|
|
} else if (mode === 'instable') {
|
|
if (chill) {
|
|
cx.strokeStyle = 'rgba(120,170,255,.9)'; cx.lineWidth = 2; cx.strokeRect(X - R, Y - R, 2 * R, 2 * R); // le kion
|
|
tri([[X, Y - R * 0.7], [X + R * 0.6, Y + R * 0.5], [X - R * 0.6, Y + R * 0.5]], 'rgba(255,120,180,.4)', 'rgba(255,150,200,.95)');
|
|
} else {
|
|
var j = function () { return (Math.sin(t * 13.1 + Math.random() * 6) ) * 9; };
|
|
tri([[X + j(), Y - R * 0.7 + j()], [X + R * 0.6 + j(), Y + R * 0.5 + j()], [X - R * 0.6 + j(), Y + R * 0.5 + j()]], 'rgba(255,120,180,.35)', 'rgba(255,150,200,.9)');
|
|
}
|
|
} else if (mode === 'morph') {
|
|
var p = [];
|
|
for (var k = 0; k < 3; k++) { var a = t * 0.6 + k * 2.094; var rr = R * (0.7 + 0.45 * Math.sin(t * 0.9 + k * 1.7));
|
|
p.push([X + Math.cos(a) * rr, Y + Math.sin(a) * rr]); }
|
|
tri(p, 'rgba(255,120,180,.32)', 'rgba(255,160,205,.95)');
|
|
} else { // éventail : n'importe quelle forme = des koins en éventail
|
|
for (var i = 0; i < n; i++) {
|
|
var a1 = t * 0.4 + i / n * 6.283, a2 = t * 0.4 + (i + 1) / n * 6.283;
|
|
var rad = R * (0.7 + 0.3 * Math.sin(i * 1.3 + t)); // contour irrégulier = « n'importe quelle forme »
|
|
var rad2 = R * (0.7 + 0.3 * Math.sin((i + 1) * 1.3 + t));
|
|
var hue = 320 + 30 * Math.sin(i + t);
|
|
tri([[X, Y], [X + Math.cos(a1) * rad, Y + Math.sin(a1) * rad], [X + Math.cos(a2) * rad2, Y + Math.sin(a2) * rad2]],
|
|
'hsla(' + hue + ',75%,65%,.25)', 'hsla(' + hue + ',80%,72%,.7)');
|
|
}
|
|
}
|
|
}
|
|
function loop() { t += 0.016; draw(); if (mode === 'morph' || mode === 'éventail' || (mode === 'instable' && !chill)) raf = requestAnimationFrame(loop); else raf = 0; }
|
|
function kick() { if (!raf && (mode === 'morph' || mode === 'éventail' || (mode === 'instable' && !chill))) raf = requestAnimationFrame(loop); else draw(); }
|
|
|
|
// drag des sommets (mode libre)
|
|
function at(e) { var r = root.getBoundingClientRect(); return [e.clientX - r.left, e.clientY - r.top]; }
|
|
cv.addEventListener('pointerdown', function (e) { if (mode !== 'libre') return; var p = at(e);
|
|
for (var i = 0; i < 3; i++) if (Math.hypot(p[0] - pts[i][0], p[1] - pts[i][1]) < 18) { drag = i; cv.setPointerCapture(e.pointerId); break; } });
|
|
cv.addEventListener('pointermove', function (e) { if (drag < 0) return; var p = at(e); pts[drag] = [Math.max(4, Math.min(W - 4, p[0])), Math.max(4, Math.min(H - 4, p[1]))]; draw(); });
|
|
cv.addEventListener('pointerup', function () { drag = -1; });
|
|
|
|
container.querySelector('.kn__bar').addEventListener('click', function (e) {
|
|
var b = e.target.closest('[data-m]'); if (!b) return; mode = b.getAttribute('data-m');
|
|
container.querySelectorAll('.kn__m').forEach(function (x) { x.classList.toggle('on', x === b); });
|
|
container.querySelector('[data-fan]').style.display = mode === 'éventail' ? 'inline' : 'none';
|
|
container.querySelector('[data-chill]').style.display = mode === 'instable' ? 'inline' : 'none';
|
|
container.querySelector('.kn__hint').textContent = mode === 'libre' ? 'libre : tire les 3 coins · le koin prend la forme que tu veux'
|
|
: mode === 'instable' ? 'le koin est INSTABLE — il tremble. « chill » le pose dans un kion (carré) où il se stabilise.'
|
|
: mode === 'éventail' ? 'n\'importe quelle forme = un éventail de koins (triangles)' : 'le koin se transforme tout seul';
|
|
if (raf) { cancelAnimationFrame(raf); raf = 0; } kick();
|
|
});
|
|
container.querySelector('[data-chill]').addEventListener('click', function () { chill = !chill; this.classList.toggle('on', chill); if (raf) { cancelAnimationFrame(raf); raf = 0; } kick(); });
|
|
container.querySelector('[data-n]').addEventListener('input', function () { n = +this.value; });
|
|
|
|
var ro = new ResizeObserver(function () { size(); draw(); }); ro.observe(root);
|
|
size(); draw();
|
|
return { unmount: function () { try { ro.disconnect(); } catch (e) {} if (raf) cancelAnimationFrame(raf); container.innerHTML = ''; } };
|
|
}
|
|
window.jOSApps = window.jOSApps || {};
|
|
window.jOSApps['koin'] = { manifest: { id: 'koin', name: 'Koin', icon: '△' }, mount: mount };
|
|
})();
|
|
</script>
|