mirror of
https://git.j0bot.ch/admin_j0bot/ploxion-cublumiere.git
synced 2026-11-29 06:22:03 +00:00
synchro du labo (0bf0da65) : app.blade.php, README.md
This commit is contained in:
parent
1b5371be6a
commit
3a01cf94d2
22
README.md
22
README.md
@ -1,3 +1,21 @@
|
||||
# ploxion-cublumiere
|
||||
# 💡 Cubes de lumière
|
||||
|
||||
PLOXION · Pose des cubes-ampoules, gros cubes-chaise et sphères de lumière dans une scène nuit. Rendu chill façon jeu vidéo : ça n'éblouit jamais. Modulaire (ledions n²) : plein de cubes assemblés = une table. · fournit: light-scene, ledion
|
||||
Pose des cubes-ampoules, gros cubes-chaise et sphères de lumière dans une scène nuit. Rendu chill façon jeu vidéo : ça n'éblouit jamais. Modulaire (ledions n²) : plein de cubes assemblés = une table.
|
||||
|
||||
| | |
|
||||
| --- | --- |
|
||||
| id | `cublumiere` |
|
||||
| fournit | `light-scene` `ledion` |
|
||||
| bions qu'il nomme | `jOSApps` `jOSPorts` |
|
||||
| fichiers | `app.blade.php` |
|
||||
| dans le labo | `resources/views/ploxions/cublumiere/` (dépôt `my_website2`) |
|
||||
|
||||
## Contribuer
|
||||
|
||||
- **Dans le xer** : https://labo.j0bot.ch/px/atelier?ploxion=cublumiere — prends-le, modifie-le, vois-le tourner, « ⧗ envoyer le tsoin ».
|
||||
- **Dans VS Code** : `xb prendre cublumiere` (ou l'extension xerboxion › ⇩ Prendre), puis ⧗ Envoyer.
|
||||
- Le chemin complet : https://labo.j0bot.ch/px/contribuer
|
||||
|
||||
Ce dépôt est un **miroir** du labo (synchronisé par `bin/ploxions-forge.mjs`, depuis le commit `0bf0da65`) : une modif se propose par un tsoin ou une branche du labo, pas directement ici.
|
||||
|
||||
© 2026 chill-tekk · ne pas nuire
|
||||
|
||||
230
app.blade.php
Normal file
230
app.blade.php
Normal file
@ -0,0 +1,230 @@
|
||||
{{-- PL0XI0N cublumiere — Cubes de lumière (RS-7 : « une ampoule dans un cube, on pose
|
||||
partout, un truc chill ; des gros cubes lumière chaise, des sphères de lumière,
|
||||
mais que ça éblouisse JAMAIS, comme dans un jeu vidéo »). Scène nocturne (forêt),
|
||||
on pose des objets lumineux (cube / gros cube-chaise / sphère) au clic/tap. Le
|
||||
rendu fait du TONE-MAPPING doux : halo additif PLAFONNÉ + cœur blanc-chaud à ~85%
|
||||
(jamais #fff pur), vignette → l'œil n'est jamais ébloui. Pulsation lente = chill.
|
||||
Persiste localStorage. Contrat jOSApps.
|
||||
+ COUCHE LEDIONS (terrain xerbot, vague 4b) : chaque device type 'led' du registre
|
||||
/xerbot-devices.json devient un cube de la scène — son glow suit on/bri/color de la
|
||||
télémétrie du bus EN LIVE (ploxion.xerbot.<id>.telemetry / .state, contrat v1) ; les
|
||||
faces du cube restent FACE6 fixes (règle RS-7). Cliquer un ledion = interrupteur
|
||||
(cmd 'set' {on} sur le bus ; le cube ne change que quand le device répond — l'état-
|
||||
vérité ne vit pas dans l'UI). Badge d'honnêteté SIM|MQTT|HA par cube + staleness 45 s
|
||||
→ hors-ligne. cublumiere est le JUMEAU VISUEL des ledions, réels ou simulés. --}}
|
||||
<style>
|
||||
.clm{height:100%;display:flex;flex-direction:column;background:#05080b;color:var(--xr-text,#dffbe9);font-family:var(--xr-font,ui-sans-serif,system-ui);box-sizing:border-box;overflow:hidden}
|
||||
.clm__stage{flex:1;position:relative;min-height:0;cursor:crosshair}
|
||||
.clm__stage canvas{position:absolute;inset:0;width:100%;height:100%;display:block}
|
||||
.clm__bar{flex:0 0 auto;display:flex;flex-wrap:wrap;align-items:center;gap:8px;padding:8px;border-top:1px solid var(--xr-border,rgba(255,200,120,.14));background:#070b10}
|
||||
.clm__seg{display:flex;gap:3px;background:rgba(255,255,255,.04);border-radius:9px;padding:3px}
|
||||
.clm__t{border:0;background:none;color:var(--xr-muted,#9bb0c0);border-radius:7px;padding:5px 9px;cursor:pointer;font:inherit;font-size:.9rem}
|
||||
.clm__t.on{background:rgba(255,210,140,.18);color:#ffd98c}
|
||||
.clm__sw{display:flex;gap:4px}
|
||||
.clm__sw button{width:18px;height:18px;border-radius:50%;border:1px solid rgba(255,255,255,.2);cursor:pointer;padding:0}
|
||||
.clm__sw button.on{outline:2px solid #fff;outline-offset:1px}
|
||||
.clm__sl{display:flex;align-items:center;gap:5px;font-size:.66rem;color:var(--xr-muted,#9bb0c0)}
|
||||
.clm__sl input{width:74px}
|
||||
.clm__b{margin-left:auto;background:none;border:1px solid var(--xr-border,rgba(255,200,120,.3));color:#ffd98c;border-radius:8px;padding:5px 9px;cursor:pointer;font:inherit;font-size:.74rem}
|
||||
.clm__b.on{background:rgba(255,210,140,.18)}
|
||||
.clm__b:not(.on)[data-leds]{opacity:.45}
|
||||
.clm__hint{position:absolute;top:8px;left:50%;transform:translateX(-50%);font-size:.66rem;color:rgba(223,251,233,.4);pointer-events:none}
|
||||
</style>
|
||||
<script>
|
||||
(function(){
|
||||
'use strict';
|
||||
var ID='cublumiere', KEY='xb-cublumiere';
|
||||
function load(){ try{ return JSON.parse(localStorage.getItem(KEY))||[]; }catch(e){ return []; } }
|
||||
function save(v){ try{ localStorage.setItem(KEY,JSON.stringify(v)); }catch(e){} }
|
||||
|
||||
function describe(){
|
||||
var v = load();
|
||||
return { v:1, id:ID, title:'Cubes de lumière', icon:'💡', items:[
|
||||
{ p:1, kind:'stat', label:'cubes créés', value:v.length }
|
||||
]};
|
||||
}
|
||||
function mount(container){
|
||||
var alive=true, raf=0, t0=Date.now();
|
||||
var objs=load();
|
||||
var tool='cube', color='#ffcf8c', intensity=0.6, size=0.5;
|
||||
// 6 couleurs de faces FIXES (RS-7 : « chaque face une couleur différente, mais fixe »)
|
||||
var FACE6=['#ff8e7a','#8ec8ff','#9bf0ad','#ffd98c','#d6b3ff','#9ee8f0'];
|
||||
container.innerHTML=
|
||||
'<div class="clm"><div class="clm__stage" data-stage><canvas data-cv></canvas>'
|
||||
+'<div class="clm__hint">clique pour poser · clique un ledion 🧊 pour l\'allumer · jamais ébloui</div></div>'
|
||||
+'<div class="clm__bar">'
|
||||
+'<div class="clm__seg" data-tools>'
|
||||
+'<button class="clm__t on" data-tool="cube" title="cube ampoule">🧊</button>'
|
||||
+'<button class="clm__t" data-tool="chair" title="gros cube-chaise lumière">🪑</button>'
|
||||
+'<button class="clm__t" data-tool="sphere" title="sphère de lumière">⚪</button>'
|
||||
+'</div>'
|
||||
+'<div class="clm__sw" data-sw></div>'
|
||||
+'<label class="clm__sl">éclat<input type="range" min="0" max="100" value="60" data-int></label>'
|
||||
+'<label class="clm__sl">taille<input type="range" min="20" max="100" value="50" data-size></label>'
|
||||
+'<button class="clm__b on" data-leds title="couche ledions — la flotte xerbot en live">🧊 ledions</button>'
|
||||
+'<button class="clm__b" data-undo>↶</button>'
|
||||
+'<button class="clm__b" data-clear>vider</button>'
|
||||
+'</div></div>';
|
||||
var root=container.querySelector('.clm'), stage=root.querySelector('[data-stage]'), cv=root.querySelector('[data-cv]'),
|
||||
swEl=root.querySelector('[data-sw]'), ctx=cv.getContext('2d');
|
||||
var COLORS=['#ffcf8c','#ffd98c','#aee3ff','#bfffd0','#ffb3c8','#d6b3ff','#fff0c8'];
|
||||
swEl.innerHTML=COLORS.map(function(c,i){ return '<button data-c="'+c+'" class="'+(i===0?'on':'')+'" style="background:'+c+'"></button>'; }).join('');
|
||||
|
||||
function persist(){ save(objs); }
|
||||
function hexRgb(h){ h=h.replace('#',''); return [parseInt(h.slice(0,2),16),parseInt(h.slice(2,4),16),parseInt(h.slice(4,6),16)]; }
|
||||
// mélange la couleur vers un blanc CHAUD plafonné à 85% (jamais blanc pur → pas d'éblouissement)
|
||||
function coreColor(rgb){ var k=0.55; var r=Math.min(217,Math.round(rgb[0]*(1-k)+255*k)); var g=Math.min(217,Math.round(rgb[1]*(1-k)+245*k)); var b=Math.min(210,Math.round(rgb[2]*(1-k)+225*k)); return 'rgb('+r+','+g+','+b+')'; }
|
||||
|
||||
function resize(){ var dpr=Math.min(2,window.devicePixelRatio||1); cv.width=stage.clientWidth*dpr; cv.height=stage.clientHeight*dpr; ctx.setTransform(dpr,0,0,dpr,0,0); }
|
||||
|
||||
function draw(){
|
||||
if(!alive) return;
|
||||
var W=stage.clientWidth, H=stage.clientHeight, time=(Date.now()-t0)/1000;
|
||||
// fond : forêt nuit (dégradé vertical sombre)
|
||||
var bg=ctx.createLinearGradient(0,0,0,H); bg.addColorStop(0,'#070d14'); bg.addColorStop(.55,'#06100e'); bg.addColorStop(1,'#040806');
|
||||
ctx.globalCompositeOperation='source-over'; ctx.fillStyle=bg; ctx.fillRect(0,0,W,H);
|
||||
// couche lumière ADDITIVE mais plafonnée
|
||||
ctx.globalCompositeOperation='lighter';
|
||||
objs.forEach(function(o){
|
||||
var x=o.x*W, y=o.y*H, base=24+o.size*120, rgb=hexRgb(o.color);
|
||||
var pulse=0.92+0.08*Math.sin(time*1.1+(o.ph||0)); // respiration lente
|
||||
var glowA=Math.min(0.46,0.16+o.intensity*0.4)*pulse; // ALPHA HALO PLAFONNÉ → jamais aveuglant
|
||||
var R=base*(0.9+o.intensity*1.3);
|
||||
var g=ctx.createRadialGradient(x,y,0,x,y,R);
|
||||
g.addColorStop(0,'rgba('+rgb[0]+','+rgb[1]+','+rgb[2]+','+glowA+')');
|
||||
g.addColorStop(0.4,'rgba('+rgb[0]+','+rgb[1]+','+rgb[2]+','+(glowA*0.4)+')');
|
||||
g.addColorStop(1,'rgba('+rgb[0]+','+rgb[1]+','+rgb[2]+',0)');
|
||||
ctx.fillStyle=g; ctx.beginPath(); ctx.arc(x,y,R,0,7); ctx.fill();
|
||||
});
|
||||
if(ledsOn) leds.forEach(function(L){ drawLedGlow(L,W,H,time); }); // glow des ledions (télémétrie live)
|
||||
// objets (forme) par-dessus, en source-over
|
||||
ctx.globalCompositeOperation='source-over';
|
||||
objs.forEach(function(o){ drawShape(o,W,H,time); });
|
||||
if(ledsOn) leds.forEach(function(L){ drawLedion(L); }); // cubes ledions + badge SIM|MQTT|HA
|
||||
// vignette douce (referme les bords → confort jeu vidéo)
|
||||
var vg=ctx.createRadialGradient(W/2,H/2,Math.min(W,H)*0.35,W/2,H/2,Math.max(W,H)*0.7);
|
||||
vg.addColorStop(0,'rgba(0,0,0,0)'); vg.addColorStop(1,'rgba(0,0,0,0.45)');
|
||||
ctx.fillStyle=vg; ctx.fillRect(0,0,W,H);
|
||||
raf=requestAnimationFrame(draw);
|
||||
}
|
||||
function drawShape(o,W,H,time){
|
||||
var x=o.x*W, y=o.y*H, s=10+o.size*30, rgb=hexRgb(o.color), core=coreColor(rgb);
|
||||
ctx.save();
|
||||
if(o.type==='sphere'){
|
||||
var gg=ctx.createRadialGradient(x-s*0.3,y-s*0.3,1,x,y,s);
|
||||
gg.addColorStop(0,core); gg.addColorStop(1,'rgba('+rgb[0]+','+rgb[1]+','+rgb[2]+',0.85)');
|
||||
ctx.fillStyle=gg; ctx.beginPath(); ctx.arc(x,y,s,0,7); ctx.fill();
|
||||
} else if(o.type==='chair'){
|
||||
// gros cube-chaise : cube isométrique haut + assise
|
||||
iso(x,y,s*1.5,rgb,core);
|
||||
ctx.fillStyle='rgba('+rgb[0]+','+rgb[1]+','+rgb[2]+',0.5)'; ctx.fillRect(x-s*1.5,y+s*0.2,s*3,s*0.5);
|
||||
} else {
|
||||
iso(x,y,s,rgb,core); // cube ampoule
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
function iso(x,y,s,rgb,core){ // cube en projection : 3 faces VISIBLES, chacune sa couleur FIXE
|
||||
// RS-7 : un gros cube LED, chaque face une couleur différente mais fixe (pas de matrice).
|
||||
var top=FACE6[4], left=FACE6[1], right=FACE6[0]; // haut / gauche / droite (3 des 6 faces visibles)
|
||||
var h=s*0.55;
|
||||
ctx.fillStyle=top; ctx.beginPath(); ctx.moveTo(x,y-h); ctx.lineTo(x+s,y-h*0.4); ctx.lineTo(x,y+h*0.2); ctx.lineTo(x-s,y-h*0.4); ctx.closePath(); ctx.fill();
|
||||
ctx.fillStyle=left; ctx.beginPath(); ctx.moveTo(x-s,y-h*0.4); ctx.lineTo(x,y+h*0.2); ctx.lineTo(x,y+h*1.0); ctx.lineTo(x-s,y+h*0.4); ctx.closePath(); ctx.fill();
|
||||
ctx.fillStyle=right; ctx.beginPath(); ctx.moveTo(x+s,y-h*0.4); ctx.lineTo(x,y+h*0.2); ctx.lineTo(x,y+h*1.0); ctx.lineTo(x+s,y+h*0.4); ctx.closePath(); ctx.fill();
|
||||
}
|
||||
|
||||
// ===== COUCHE LEDIONS — la flotte xerbot en live (jumeau visuel, contrat v1) ==========
|
||||
// Chaque device type 'led' de /xerbot-devices.json = un cube posé au bord de la scène.
|
||||
// on/bri/color suivent la télémétrie du bus (ploxion.xerbot.<id>.telemetry / .state) ;
|
||||
// sans nouvelle du device depuis 45 s (stale_s du contrat) → réputé hors-ligne.
|
||||
var leds=[], ledsOn=true, ledOffs=[];
|
||||
var STALE_MS=45000;
|
||||
function ledUid(){ return 'clm-'+Date.now().toString(36)+'-'+Math.random().toString(36).slice(2,8); }
|
||||
function transportDe(p,dflt){ var t=p&&p.__transport; return t==='mqtt'?'MQTT':(t==='ha'?'HA':(dflt||'SIM')); }
|
||||
function majLed(L,p){
|
||||
if(!p||typeof p!=='object') return;
|
||||
if(p.on!=null) L.st.on=!!p.on;
|
||||
if(p.bri!=null){ var b=Number(p.bri); if(isFinite(b)) L.st.bri=Math.max(0,Math.min(255,Math.round(b))); }
|
||||
if(Array.isArray(p.color)&&p.color.length>=3) L.st.color=[p.color[0]|0,p.color[1]|0,p.color[2]|0];
|
||||
if(p.online!=null) L.st.online=!!p.online;
|
||||
L.st.badge=transportDe(p,L.st.badge);
|
||||
L.st.vu=Date.now();
|
||||
}
|
||||
try{
|
||||
fetch('/xerbot-devices.json').then(function(r){ return r.ok?r.json():null; }).then(function(d){
|
||||
var liste=d&&Array.isArray(d.devices)?d.devices:(Array.isArray(d)?d:[]);
|
||||
var n=0;
|
||||
liste.forEach(function(dev){
|
||||
if(!dev||dev.type!=='led'||!dev.id) return;
|
||||
var L={ id:String(dev.id), name:String(dev.name||dev.id).slice(0,30),
|
||||
x:0.16+(n%5)*0.17, y:0.82+Math.floor(n/5)*0.09,
|
||||
st:{ on:false, bri:128, color:[255,170,60], online:false, vu:0,
|
||||
badge:(dev.transport==='mqtt'?'MQTT':dev.transport==='ha'?'HA':'SIM') } };
|
||||
leds.push(L); n++;
|
||||
if(window.jOSPorts&&window.jOSPorts.on){
|
||||
ledOffs.push(window.jOSPorts.on('ploxion.xerbot.'+L.id+'.telemetry',function(p){ majLed(L,p); }));
|
||||
ledOffs.push(window.jOSPorts.on('ploxion.xerbot.'+L.id+'.state',function(p){ majLed(L,p); }));
|
||||
}
|
||||
});
|
||||
}).catch(function(){});
|
||||
}catch(e){}
|
||||
function ledVivant(L){ return L.st.online&&(Date.now()-L.st.vu)<STALE_MS; }
|
||||
function drawLedion(L){
|
||||
var W=stage.clientWidth,H=stage.clientHeight,st=L.st,vivant=ledVivant(L);
|
||||
var x=L.x*W,y=L.y*H,s=22;
|
||||
ctx.save();
|
||||
ctx.globalAlpha=vivant?1:0.35; // hors-ligne : cube fantôme
|
||||
iso(x,y,s,st.color,null); // faces FACE6 fixes (règle RS-7)
|
||||
ctx.globalAlpha=1;
|
||||
ctx.font='10px system-ui,sans-serif'; ctx.textAlign='center';
|
||||
ctx.fillStyle='rgba(223,251,233,0.72)';
|
||||
ctx.fillText('🧊 '+L.name,x,y+s*1.05);
|
||||
// badge d'honnêteté par cube : SIM (simulé) | MQTT | HA (réels)
|
||||
ctx.fillStyle=st.badge==='MQTT'?'#8ec8ff':(st.badge==='HA'?'#9bf0ad':'#ffd98c');
|
||||
ctx.fillText(vivant?st.badge+(st.on?' · on':' · off'):st.badge+' · hors-ligne',x,y+s*1.05+12);
|
||||
ctx.restore();
|
||||
}
|
||||
function drawLedGlow(L,W,H,time){
|
||||
var st=L.st;
|
||||
if(!ledVivant(L)||!st.on||st.bri<=0) return;
|
||||
var x=L.x*W,y=L.y*H,k=st.bri/255;
|
||||
var glowA=Math.min(0.46,0.1+0.36*k)*(0.92+0.08*Math.sin(time*1.1)); // même plafond anti-éblouissement
|
||||
var R=40+130*k, c=st.color;
|
||||
var g=ctx.createRadialGradient(x,y,0,x,y,R);
|
||||
g.addColorStop(0,'rgba('+c[0]+','+c[1]+','+c[2]+','+glowA+')');
|
||||
g.addColorStop(0.4,'rgba('+c[0]+','+c[1]+','+c[2]+','+(glowA*0.4)+')');
|
||||
g.addColorStop(1,'rgba('+c[0]+','+c[1]+','+c[2]+',0)');
|
||||
ctx.fillStyle=g; ctx.beginPath(); ctx.arc(x,y,R,0,7); ctx.fill();
|
||||
}
|
||||
|
||||
stage.addEventListener('click',function(e){
|
||||
var r=stage.getBoundingClientRect(), px=e.clientX-r.left, py=e.clientY-r.top;
|
||||
// clic sur un ledion = interrupteur → cmd 'set' sur le bus ; le cube ne change que
|
||||
// quand le device (sim ou réel) répond par sa télémétrie (l'état-vérité n'est pas ici)
|
||||
if(ledsOn){
|
||||
for(var i=0;i<leds.length;i++){
|
||||
var L=leds[i], dx=px-L.x*r.width, dy=py-L.y*r.height;
|
||||
if(dx*dx+dy*dy<28*28){
|
||||
try{ if(window.jOSPorts&&window.jOSPorts.emit) window.jOSPorts.emit('xerbot',L.id+'.cmd',{id:ledUid(),cmd:'set',args:{on:!L.st.on},src:'cublumiere',ts:Date.now()}); }catch(x){}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
objs.push({type:tool,x:px/r.width,y:py/r.height,color:color,intensity:intensity,size:size,ph:objs.length*0.7});
|
||||
persist();
|
||||
});
|
||||
root.querySelector('[data-tools]').addEventListener('click',function(e){ var b=e.target.closest('[data-tool]'); if(!b)return; tool=b.getAttribute('data-tool'); root.querySelectorAll('[data-tool]').forEach(function(x){x.classList.toggle('on',x===b);}); });
|
||||
swEl.addEventListener('click',function(e){ var b=e.target.closest('[data-c]'); if(!b)return; color=b.getAttribute('data-c'); swEl.querySelectorAll('button').forEach(function(x){x.classList.toggle('on',x===b);}); });
|
||||
root.querySelector('[data-int]').addEventListener('input',function(e){ intensity=e.target.value/100; });
|
||||
root.querySelector('[data-size]').addEventListener('input',function(e){ size=e.target.value/100; });
|
||||
root.querySelector('[data-leds]').addEventListener('click',function(e){ ledsOn=!ledsOn; e.target.classList.toggle('on',ledsOn); });
|
||||
root.querySelector('[data-undo]').addEventListener('click',function(){ objs.pop(); persist(); });
|
||||
root.querySelector('[data-clear]').addEventListener('click',function(){ objs=[]; persist(); });
|
||||
|
||||
var ro=null; try{ ro=new ResizeObserver(resize); ro.observe(stage); }catch(e){ window.addEventListener('resize',resize); }
|
||||
resize(); draw();
|
||||
return { unmount:function(){ alive=false; if(raf)cancelAnimationFrame(raf); try{ro&&ro.disconnect();}catch(e){} ledOffs.forEach(function(off){ try{off();}catch(e){} }); container.innerHTML=''; } };
|
||||
}
|
||||
window.jOSApps=window.jOSApps||{};
|
||||
window.jOSApps[ID]={manifest:{id:ID,name:'Cubes de lumière',icon:'💡'},mount: mount, describe: describe};
|
||||
})();
|
||||
</script>
|
||||
Loading…
Reference in New Issue
Block a user