Widget:TwinSuns: Difference between revisions

From WyrdeWiki
No edit summary
No edit summary
 
(14 intermediate revisions by the same user not shown)
Line 1: Line 1:
<noinclude>__NOTOC__
<noinclude>__NOTOC__
This widget displays WyrdeHaven’s Twin Suns with seasonal wobble and calendar.
This widget shows WyrdeHaven’s twin suns with seasonal wobble & calendar.


=Usage=
=Usage=
Line 6: Line 6:
  | id=ts1
  | id=ts1
  | size=768
  | size=768
  | fps=8
  | fps=5
  | seasonAmpDeg=2.5
| wobble=5
  | wobbleSepDeg=2.5
| equator=8
  | solaraUrl=https://www.wyrdehavenchronicl.es/wiki/images/f/fe/Solara.png
  | sep=2.5
  | vaelusUrl=https://www.wyrdehavenchronicl.es/wiki/images/7/7a/Vaelus.png
  | degpx=10
  | skyUrl=http://wyrdehavenchronicl.es/images/WyrdeHaven_Sky.png
  | solara=https://www.wyrdehavenchronicl.es/wiki/images/f/fe/Solara.png
  | cosUrl=http://wyrdehavenchronicl.es/images/Cosinus.png
  | vaelus=https://www.wyrdehavenchronicl.es/wiki/images/7/7a/Vaelus.png
  | sky=http://wyrdehavenchronicl.es/images/WyrdeHaven_Sky.png
  | cos=http://wyrdehavenchronicl.es/images/Cosinus.png
}}
}}
{| class="wikitable"
|-
! param !! meaning !! default
|-
| size || max stage width (px) || 768
|-
| fps || play speed (frames/s) || 5
|-
| wobble || solar relative wobble amplitude (Δ, degrees) || 2.5
|-
| equator || seasonal/barycenter max tilt (degrees) || 8
|-
| sep || visible horizontal separation between suns (degrees) || 2.5
|-
| degpx || vertical degree→pixel scale (px per degree) || 10
|}
</noinclude><includeonly>
</noinclude><includeonly>
<div class="wh-twinsuns" style="max-width:<!--{$size|default:768|escape:'html'}-->px;margin:1rem 0;">
<div class="wh-twins" style="max-width:<!--{$size|default:768|escape:'html'}-->px;margin:1rem 0;">
   <!-- centered day number above the slider -->
   <!-- centered day label -->
   <div style="text-align:center;margin-bottom:.25rem;">
   <div id="<!--{$id|default:'ts'|escape:'html'}-->-daylabel"
    <span id="<!--{$id|default:'ts'|escape:'html'}-->-daynum">1</span> / 479
      style="text-align:center;font-weight:600;margin-bottom:.25rem;">1 / 479</div>
  </div>


   <!-- slider + cosine (cosine sits behind, same width) -->
   <!-- slider + cosine -->
   <div style="position:relative;display:flex;align-items:center;gap:.5rem;">
   <div style="position:relative;display:flex;align-items:center;gap:.5rem;">
     <img id="<!--{$id|default:'ts'|escape:'html'}-->-cos"
     <img id="<!--{$id|default:'ts'|escape:'html'}-->-cos"
         src="<!--{$cosUrl|default:'http://wyrdehavenchronicl.es/images/Cosinus.png'|escape:'html'}-->"
         src="<!--{$cos|escape:'html'}-->"
         alt="Cosine"
         alt="" decoding="async"
         style="position:absolute;left:0;right:2.2rem;height:22px;object-fit:fill;opacity:.6;pointer-events:none;"/>
         style="position:absolute;left:0;right:2.25rem;top:50%;transform:translateY(-50%);opacity:.6;pointer-events:none;width:calc(100% - 2.25rem);height:auto;"/>
     <input id="<!--{$id|default:'ts'|escape:'html'}-->-x" type="range" min="1" max="479" value="1"
     <input id="<!--{$id|default:'ts'|escape:'html'}-->-x" type="range" min="1" max="479" value="1"
           style="flex:1;position:relative;z-index:1;">
           style="flex:1;position:relative;z-index:1;">
     <button id="<!--{$id|default:'ts'|escape:'html'}-->-play"
     <button id="<!--{$id|default:'ts'|escape:'html'}-->-play"
             style="font-size:1rem;padding:.2rem .5rem;cursor:pointer;min-width:2rem;">▶</button>
             style="font-size:1rem;padding:.2rem .5rem;cursor:pointer;">▶</button>
   </div>
   </div>


   <!-- add breathing room below the slider so text never crosses the cosine -->
   <!-- date line moved slightly lower to avoid cosine overlap -->
  <div style="height:.5rem"></div>
   <div style="margin:2rem 0 .4rem 0;">
 
   <div style="margin:.25rem 0 .5rem 0;">
     <strong>Date:</strong>
     <strong>Date:</strong>
     <span id="<!--{$id|default:'ts'|escape:'html'}-->-datestr">Fortnight of Renewal (Dawning), day 8</span>
     <span id="<!--{$id|default:'ts'|escape:'html'}-->-date">Fortnight of Renewal (Dawning), day 8 (FR 8)</span>
   </div>
   </div>


   <!-- stage -->
   <!-- stage -->
   <div id="<!--{$id|default:'ts'|escape:'html'}-->-stage"
   <div id="<!--{$id|default:'ts'|escape:'html'}-->-stage"
       style="position:relative;width:100%;aspect-ratio:3/2;isolation:isolate;border:1px solid #333;background:#000;overflow:hidden;">
       style="position:relative;width:100%;aspect-ratio:3/2;isolation:isolate;background:#000;border:1px solid #333;overflow:hidden;">
     <img id="<!--{$id|default:'ts'|escape:'html'}-->-sky"
     <img id="<!--{$id|default:'ts'|escape:'html'}-->-sky"
         src="<!--{$skyUrl|default:'http://wyrdehavenchronicl.es/images/WyrdeHaven_Sky.png'|escape:'html'}-->"
         src="<!--{$sky|escape:'html'}-->" alt="Sky" decoding="async"
        alt="Sky backdrop"
         style="position:absolute;inset:0;object-fit:contain;object-position:center;z-index:1;width:100%;height:100%;"/>
        decoding="async" fetchpriority="high" draggable="false"
     <img id="<!--{$id|default:'ts'|escape:'html'}-->-solara"
         style="position:absolute;inset:0;width:100%;height:100%;object-fit:cover;object-position:center;z-index:1;"/>
         src="<!--{$solara|escape:'html'}-->" alt="Solara"
    <!-- suns -->
         style="position:absolute;z-index:3;transform:translate(-50%,-50%);"/>
     <img id="<!--{$id|default:'ts'|escape:'html'}-->-sol"
     <img id="<!--{$id|default:'ts'|escape:'html'}-->-vaelus"
         src="<!--{$solaraUrl|default:'https://www.wyrdehavenchronicl.es/wiki/images/f/fe/Solara.png'|escape:'html'}-->"
         src="<!--{$vaelus|escape:'html'}-->" alt="Vaelus"
        alt="Solara"
         style="position:absolute;z-index:2;transform:translate(-50%,-50%);"/>
         style="position:absolute;transform:translate(-50%,-50%);z-index:3;pointer-events:none;"/>
     <img id="<!--{$id|default:'ts'|escape:'html'}-->-vae"
         src="<!--{$vaelusUrl|default:'https://www.wyrdehavenchronicl.es/wiki/images/7/7a/Vaelus.png'|escape:'html'}-->"
        alt="Vaelus"
         style="position:absolute;transform:translate(-50%,-50%);z-index:2;pointer-events:none;"/>
   </div>
   </div>


   <div style="margin:.5rem 0 0 0;">
   <div style="margin-top:.5rem;">
     <div><strong>Relative Solar Inclination (Δ):</strong> <span id="<!--{$id|default:'ts'|escape:'html'}-->-delta">+2.50°</span> <span id="<!--{$id|default:'ts'|escape:'html'}-->-phase">(Closing)</span></div>
     <div><strong>Relative Solar Inclination (Δ):</strong>
     <div><strong>Seasonal Equatorial Inclination (barycenter):</strong> <span id="<!--{$id|default:'ts'|escape:'html'}-->-season">+0.00°</span></div>
      <span id="<!--{$id|default:'ts'|escape:'html'}-->-relinc">+2.50° (Closing)</span>
    </div>
     <div><strong>Seasonal Equatorial Inclination (barycenter):</strong>
      <span id="<!--{$id|default:'ts'|escape:'html'}-->-eqinc">-8.00°</span>
    </div>
   </div>
   </div>
</div>
</div>
Line 70: Line 84:
   var ID  = "<!--{$id|default:'ts'|escape:'js'}-->";
   var ID  = "<!--{$id|default:'ts'|escape:'js'}-->";
   var FPS = parseFloat("<!--{$fps|default:5|escape:'js'}-->") || 5;
   var FPS = parseFloat("<!--{$fps|default:5|escape:'js'}-->") || 5;
  var WOBBLE  = parseFloat("<!--{$wobble|default:2.5|escape:'js'}-->") || 2.5; // observable Δ (deg)
  var EQUATOR = parseFloat("<!--{$equator|default:8|escape:'js'}-->")  || 8;  // seasonal max (deg)
  var SEP    = parseFloat("<!--{$sep|default:2.5|escape:'js'}-->")    || 2.5; // horizontal sep (deg)
  var DEGPX  = parseFloat("<!--{$degpx|default:10|escape:'js'}-->")  || 10;  // px per degree


   // Configurable amplitudes (degrees)
   // Find and init exactly one instance in a given DOM scope
  var SEASON_AMP = parseFloat("<!--{$seasonAmpDeg|default:2.5|escape:'js'}-->") || 2.5;   // barycenter (seasonal) amplitude
  function initIn(root){
  var WOBBLE_SEP = parseFloat("<!--{$wobbleSepDeg|default:2.5|escape:'js'}-->") || 2.5;   // total Solara–Vaelus separation cue
    var wrap = root.querySelector('.wh-twins');
    if(!wrap) return;


  function ge(s){ return document.getElementById(ID + s); }
    function ge(s){ return document.getElementById(ID + s); }
  var el = {
    var el = {
    daynum: ge("-daynum"),
      day: ge("-daylabel"),
    x:     ge("-x"),
      rng: ge("-x"),
    play:   ge("-play"),
      play: ge("-play"),
    cos:   ge("-cos"),
      date: ge("-date"),
    stage: ge("-stage"),
      stage: ge("-stage"),
    sky:   ge("-sky"),
      sky: ge("-sky"),
    sol:   ge("-sol"),
      s: ge("-solara"),
    vae:   ge("-vae"),
      v: ge("-vaelus"),
    dates: ge("-datestr"),
      rel: ge("-relinc"),
    delta: ge("-delta"),
      eq: ge("-eqinc")
     phase:  ge("-phase"),
     };
    season: ge("-season")
    for (var k in el){ if(!el[k]) return; } // quietly bail if something’s missing
  };


  // keep cosine exactly behind the slider track
    var TAU = Math.PI*2;
  function syncCosWidth(){
    function cosPhase(d){ return Math.cos(TAU*((d-1)/479)); }
    var r = el.x.getBoundingClientRect();
     function fmtDeg(x){ var s=(x>=0?"+":""); return s + x.toFixed(2) + "°"; }
     var C = el.cos;
     function openingClosing(_, phase){
    C.style.left = "0";
      var s = Math.sin(TAU*phase);
    C.style.right = (r.height + 6) + "px"; // reserve space for the play button
      return (-s>0) ? "Closing" : "Opening";
     C.style.top = ((r.height - 22)/2) + "px";
    }
  }
  window.addEventListener("resize", syncCosWidth);


  // calendar helpers
    var months = ["Primaris","Vernalis","Tharion","Lunarae","Cindrel","Solvane","Auren","Veyrath","Rhendol","Tirien","Gairos","Fenmir","Wyrdrun","Cernis","Eirathen"];
  var months = ["Primaris","Vernalis","Tharion","Lunarae","Cindrel","Solvane","Auren","Veyrath","Rhendol","Tirien","Gairos","Fenmir","Wyrdrun","Cernis","Eirathen"];
    function dateText(d){
 
      if(d<=7)       return "Fortnight of Renewal (Dawning), day " + (d+7) + " (FR " + (d+7) + ")";
  function dateLabel(d){
      if(d>=473){var k=d-472; return "Fortnight of Renewal (Fading), day " + k + " (FR " + k + ")";}
    // d: 1..479  (year starts at midwinter)
      var n=d-7, m=Math.ceil(n/31), day=((n-1)%31)+1; return day + " " + months[m-1];
    if(d <= 7){
      return "Fortnight of Renewal (Dawning), day " + (d+7) + " (FR " + (d+7) + ")";
     }
     }
    if(d >= 473){
      var k = d - 472; // 1..7
      return "Fortnight of Renewal (Fading), day " + k + " (FR " + k + ")";
    }
    // months: 15 × 31 days = 465
    var n = d - 7; // 1..465
    var mIndex = Math.floor((n-1)/31); // 0..14
    var dayInMonth = ((n-1)%31) + 1;
    return dayInMonth + " " + months[mIndex];
  }


  // trig helpers
    var SOL_SHARE=1.0, VAE_SHARE=1.5, SUM=SOL_SHARE+VAE_SHARE;
  var TWO_PI = Math.PI*2;
  function cosCycle(day){ return Math.cos(TWO_PI * (day-1) / 479); } // day 1 -> +1 (midwinter max)


  // mapping degrees->pixels; assume ~90° sky spans full stage height -> tweakable if needed
    function setStarSizes(){
  function pxPerDeg(){
      var w = el.stage.clientWidth || el.stage.getBoundingClientRect().width || 0;
    var h = el.stage.clientHeight;
      if(!w) return;
    return h / 90; // 1° ≈ stageHeight/90
      var base = Math.round(w*0.08);
  }
      el.s.width = el.s.height = base;
      el.v.width = el.v.height = Math.round(base*0.8);
    }


  // place suns
    function update(){
  function layout(day){
      try{
    // seasonal declination (barycenter)
        var d = parseInt(el.rng.value,10) || 1;
    var seasonDeg = SEASON_AMP * cosCycle(day);
        var phase = (d-1)/479;


    // relative split stays constant at WOBBLE_SEP; Solara above when positive season phase starts (day 1)
        // Your “observable” Δ already in sky-arc degrees
    var halfSep = WOBBLE_SEP / 2;
        var delta = (WOBBLE * cosPhase(d)) / 8;    // ±WOBBLE
        var eq    = -EQUATOR * cosPhase(d);  // lowest at midwinter


    // pixel mapping
        el.day.textContent  = d + " / 479";
    var k = pxPerDeg();
        el.date.textContent = dateText(d);
        el.rel.textContent  = fmtDeg(delta) + " (" + openingClosing(delta, phase) + ")";
        el.eq.textContent  = fmtDeg(eq);


    var stageRect = el.stage.getBoundingClientRect();
        var w = el.stage.clientWidth, h = el.stage.clientHeight;
    var W = el.stage.clientWidth, H = el.stage.clientHeight;
        if(!w||!h) return;


    // center X for both suns
        var cx = w*0.5, cy = h*0.33;
    var cx = W * 0.50;
        var dx = (SEP/2)*DEGPX;


    // base vertical position near upper third of sky
        var solOff =  (delta*(SOL_SHARE/SUM))*DEGPX;
    var baseY = H * 0.28;
        var vaeOff = -(delta*(VAE_SHARE/SUM))*DEGPX;
        var yBase  = cy - (eq*DEGPX);


    var ySeason = baseY - (seasonDeg * k);
        el.s.style.left = (cx - dx) + "px";
    var ySol = ySeason - (halfSep * k);
        el.v.style.left = (cx + dx) + "px";
    var yVae = ySeason + (halfSep * k);
        el.s.style.top  = (yBase - solOff) + "px";
        el.v.style.top  = (yBase - vaeOff) + "px";
      }catch(e){}
    }


     // set sizes (Solara bigger than Vaelus, keep proportion within 256 canvas scale)
     function ensureSizedThen(fn){
    var solSize = Math.round(Math.min(W, H) * 0.14);
      setStarSizes();
    var vaeSize = Math.round(solSize * 0.65);
      if(el.stage.clientWidth) fn();
      else setTimeout(function(){ ensureSizedThen(fn); }, 50);
    }


     Object.assign(el.sol.style, { left: cx+"px", top: ySol+"px", width: solSize+"px", height: "auto" });
     var timer=null, playing=false, interval=1000/Math.max(1,FPS);
     Object.assign(el.vae.style, { left: cx+"px", top: yVae+"px", width: vaeSize+"px", height: "auto" });
     function step(){ var v=parseInt(el.rng.value,10)||1; el.rng.value=(v>=479)?1:(v+1); update(); }


     // texts
     el.rng.addEventListener("input", update);
     el.delta.textContent = (WOBBLE_SEP >= 0 ? "+" : "") + WOBBLE_SEP.toFixed(2) + "°";
     el.play.addEventListener("click", function(){
    el.season.textContent = (seasonDeg>=0?"+":"") + seasonDeg.toFixed(2) + "°";
      if(!playing){ playing=true; el.play.textContent="■"; timer=setInterval(step, interval); }
      else { playing=false; el.play.textContent="▶"; clearInterval(timer); timer=null; }
    });
    window.addEventListener("resize", function(){ setStarSizes(); update(); });


     // Opening/Closing: |season| increasing -> Opening; decreasing -> Closing
     ensureSizedThen(update);
    // derivative sign of |A cos| at day ~ compare neighboring days
    var eps = 1;
    var prev = Math.abs(SEASON_AMP * cosCycle(Math.max(1, day-eps)));
    var next = Math.abs(SEASON_AMP * cosCycle(Math.min(479, day+eps)));
    el.phase.textContent = (next > prev) ? "(Opening)" : "(Closing)";
   }
   }


   function update(){
   // Run on normal load
     var d = parseInt(el.x.value,10);
  if (document.readyState === "complete" || document.readyState === "interactive"){
    el.daynum.textContent = d;
     initIn(document);
     el.dates.textContent  = dateLabel(d);
  } else {
    layout(d);
     document.addEventListener("DOMContentLoaded", function(){ initIn(document); }, {once:true});
   }
   }


   // scrub throttle
   // Also run when MediaWiki injects content (tabs, previews, etc.)
  var raf = null;
  if (window.mw && mw.hook) {
  el.x.addEventListener("input", function(){
     mw.hook('wikipage.content').add(function($c){
    if(raf) return;
      initIn($c && $c[0] ? $c[0] : document);
     raf = requestAnimationFrame(function(){ raf=null; update(); });
     });
  });
 
  // play/pause
  var timer=null, playing=false, interval=1000/Math.max(1,FPS);
  function step(){
    var v = parseInt(el.x.value,10);
    v = (v>=479)?1:(v+1);
     el.x.value = v;
    update();
   }
   }
  el.play.addEventListener("click", function(){
    if(!playing){
      playing=true; el.play.textContent="■";
      timer = setInterval(step, interval);
    }else{
      playing=false; el.play.textContent="▶";
      clearInterval(timer); timer=null;
    }
  });
  // initial sync
  syncCosWidth();
  update();
})();
})();
</script>
</script>
</includeonly>
</includeonly>

Latest revision as of 21:50, 11 November 2025

This widget shows WyrdeHaven’s twin suns with seasonal wobble & calendar.

Usage

1 / 479
Date: Fortnight of Renewal (Dawning), day 8 (FR 8)
Sky Solara Vaelus
Relative Solar Inclination (Δ): +2.50° (Closing)
Seasonal Equatorial Inclination (barycenter): -8.00°

param meaning default
size max stage width (px) 768
fps play speed (frames/s) 5
wobble solar relative wobble amplitude (Δ, degrees) 2.5
equator seasonal/barycenter max tilt (degrees) 8
sep visible horizontal separation between suns (degrees) 2.5
degpx vertical degree→pixel scale (px per degree) 10