diff options
-rw-r--r-- | libs/music/player.d/main_static.js | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/libs/music/player.d/main_static.js b/libs/music/player.d/main_static.js index b830a51..bb2c112 100644 --- a/libs/music/player.d/main_static.js +++ b/libs/music/player.d/main_static.js @@ -40,7 +40,7 @@ class Ink } draw(cctx) { - cctx.drawImage(NSInk.inkimg[this.color],this.x+5*window.devicePixelRatio,this.y+5*window.devicePixelRatio); + cctx.drawImage(NSInk.inkimg[this.color], this.x - 5 * window.devicePixelRatio, this.y - 5 * window.devicePixelRatio); } } @@ -761,6 +761,7 @@ NSInk={ debug_render:false, erms_tracker:new TrendTracker(8, 0), freq_tracker:[], + max_droplets:1536, inkPrepare:function() { for(let i = 0; i < 7; ++i) @@ -788,13 +789,16 @@ NSInk={ if(!this.inks[i].active) {this.inks[i]=new Ink(_vx,_vy,_c1,_c2);return;} } - if(this.inks.length<1024)this.inks.push(new Ink(_vx,_vy,_c1,_c2)); + if (this.inks.length < NSInk.max_droplets) this.inks.push(new Ink(_vx, _vy, _c1, _c2)); }, update:function() { const canvas=NSUI.canvas; const cctx=canvas.getContext('2d'); cctx.clearRect(0,0,canvas.width,canvas.height); + if (!NSAudio || !NSAudio.anlznode) return; + const origblend = cctx.globalCompositeOperation; + cctx.globalCompositeOperation = "screen"; try{ let amplarr = new Float32Array(NSAudio.anlznode.frequencyBinCount); let freqarr = new Float32Array(NSAudio.anlznode.frequencyBinCount); @@ -844,20 +848,36 @@ NSInk={ freq_velocity_variances[i] = Math.min(base_velocity_factor * 0.5, Math.pow(evals[i] * 10, 0.5)); actual_emission[i] = 0; - if (r - this.ifcaps[i] > 5) + const sustained1 = Math.abs(this.freq_tracker[i].slope) < 0.00125 && (evals[i] * (i > 4 ? 2 : 1)) > 0.5; + const sustained2 = Math.abs(this.freq_tracker[i].slope) < 0.00075 && (evals[i] * (i > 4 ? 2 : 1)) > 0.3; + let emit = false; + emit |= (r - this.ifcaps[i] > 5); + emit |= (sustained1 || sustained2); + if (sustained1) freq_emission_factors[i] /= 5; + if (sustained2) freq_emission_factors[i] /= 10; + if (emit) { - let color=i; actual_emission[i] = base_emission_factor * base_emission_modifier * freq_emission_factors[i] * freq_emission_modifiers[i]; - actual_emission[i] = Math.min(Math.max(Math.floor(actual_emission[i]), 1), 24); - for(let k = 0; k < actual_emission[i]; ++k) + const emission = actual_emission[i] < 0.075 ? 0 : Math.min(Math.max(Math.floor(actual_emission[i]), 1), 24); + for(let k = 0; k < emission; ++k) { const rad = Math.random() * Math.PI * 2; const vel = (base_velocity_factor + freq_velocity_shift[i]) * 0.25 + (Math.random() * 2 - 1) * freq_velocity_variances[i]; - this.createInk(vel * Math.cos(rad), vel * Math.sin(rad), color, base_veldamp_factor); + this.createInk(vel * Math.cos(rad), vel * Math.sin(rad), i, base_veldamp_factor); } } if (r > this.ifcaps[i]) this.ifcaps[i] = r; else this.ifcaps[i] -= 3; } + for (let i = 0; i < 7; ++i) + { + const multi = [1, 1, 1.1, 1.25, 1.65, 2.5, 2.4]; + const v = Math.pow(Math.min(evals[i] * multi[i], 1), 2); + const r = 10 + 110 * v; + cctx.fillStyle = `${NSInk.ic2[i].slice(0, -4)}${0.3 + 0.5 * v})`; + cctx.beginPath(); + cctx.ellipse(NSUI.canvas.width / 2, NSUI.canvas.height / 2, r, r, 0, 0, 2 * Math.PI); + cctx.fill(); + } if (this.debug_render) { const debug_render_bars = function(data, n, max, bipolar, style) { const cw = NSUI.canvas.width; @@ -883,6 +903,7 @@ NSInk={ cctx.fillStyle = NSInk.ic1[i]; cctx.fillText(evals[i].toFixed(2), i / 7 * NSUI.canvas.width + 8, 180); cctx.fillText(this.freq_tracker[i].slope.toFixed(4).padStart(7), i / 7 * NSUI.canvas.width + 8, 210); + cctx.fillText(actual_emission[i].toFixed(4).padStart(7), i / 7 * NSUI.canvas.width + 8, 240); } } }catch(e){ @@ -892,6 +913,7 @@ NSInk={ let aa=0; for(let i=0;i<this.inks.length;++i) if(this.inks[i].active){this.inks[i].draw(cctx);this.inks[i].update();++aa;} + cctx.globalCompositeOperation = origblend; cctx.fillStyle=window.getComputedStyle(document.body).getPropertyValue("--principal-fg"); cctx.font="2em 'CMU Typewriter Text w', 'CMU Typewriter Text', 'TeX Gyre Cursor', 'FreeMono', 'Courier New', Courier, monospace"; cctx.fillText(`Active droplets ${aa}`,0,52); |