0xa89f3db4…071asent to0xecb92cc7…1463·#25,067,890·view on Etherscan
sconnect()}catch(e){}this._sourceNode=null}this.isPlaying=!1}startDirectional(e=!0){const t=this._savedDirectionalPosition>0?this._savedDirectionalPosition:e?0:this._forwardBuffer?this._forwardBuffer.duration:0;this._directionalEnabled?this.playDirectional(t,e):this.initDirectionalPlayback().then(()=>{this._directionalEnabled&&this.playDirectional(t,e)})}analyze(){if(this._simulating)return void this._simulateAudio();if(!this._analyser)return;this._analyser.getByteFrequencyData(this._spectrum),this._analyser.getByteTimeDomainData(this._waveform);let e=0;for(let t=0;t<this._waveform.length;t++){const i=(this._waveform[t]-128)/128;e+=i*i}this._amplitude=Math.sqrt(e/this._waveform.length),this._calculateEnergyBands();const t=performance.now();this._energy.bass>this.beatThreshold&&t-this.lastBeatTime>this.beatCooldown?(this.beatDetected=!0,this.lastBeatTime=t):this.beatDetected=!1}_simulateAudio(){const e=this._simTime;this._simTime+=.016;const t=1024;this._simSpectrum||(this._simSpectrum=new Uint8Array(t),this._simWaveform=new Uint8Array(t));const i=.4+.35*Math.sin(.7*e)+.15*Math.sin(1.3*e),a=.25+.2*Math.sin(1.1*e+1)+.1*Math.sin(2.7*e),s=.1+.12*Math.sin(1.9*e+2)+.08*Math.sin(4.1*e);for(let o=0;o<t;o++){const r=o/t,n=i*Math.max(0,1-7*r)*255,l=a*Math.exp(-((r-.25)**2)/.008)*200,h=s*Math.exp(-((r-.6)**2)/.03)*150,d=12*Math.sin(.3*o+3*e)+6*Math.sin(.7*o+5*e);this._simSpectrum[o]=Math.max(0,Math.min(255,n+l+h+d))}for(let o=0;o<t;o++){const r=o/t*Math.PI*2,n=30*Math.sin(4*r+3*e)*i+15*Math.sin(11*r+7*e)*a+8*Math.sin(23*r+13*e)*s;this._simWaveform[o]=Math.max(0,Math.min(255,128+n))}this._spectrum=this._simSpectrum,this._waveform=this._simWaveform;let o=0;for(let e=0;e<t;e++){const t=(this._simWaveform[e]-128)/128;o+=t*t}this._amplitude=Math.sqrt(o/t),this._energy.bass=.8*i,this._energy.lowMid=.3*i+.5*a,this._energy.mid=.7*a,this._energy.highMid=.3*a+.5*s,this._energy.treble=.6*s;const r=performance.now();i>.6&&Math.sin(2.3*e)>.7&&r-this.lastBeatTime>2*this.beatCooldown?(this.beatDetected=!0,this.lastBeatTime=r):this.beatDetected=!1}_calculateEnergyBands(){const e=this._getContext().sampleRate/2,t=this._analyser.frequencyBinCount;Object.keys(this.energyBands).forEach(i=>{const[a,s]=this.energyBands[i],o=Math.floor(a/e*t),r=Math.min(Math.ceil(s/e*t),t-1);let n=0,l=0;for(let e=o;e<=r;e++)n+=this._spectrum[e],l++;this._energy[i]=l>0?n/l/255:0})}getSpectrum(){return this._spectrum||new Uint8Array(1024)}getWaveform(){return this._waveform||new Uint8Array(1024)}getEnergy(e){return this._energy[e]||0}getAllEnergy(){return{...this._energy}}getAmplitude(){return this._amplitude}isBeat(){return this.beatDetected}hasAudio(){return this.isLoaded}getCentroid(){if(!this._spectrum)return 0;const e=this._getContext().sampleRate/2;let t=0,i=0;for(let a=0;a<this._spectrum.length;a++){t+=a/this._spectrum.length*e*this._spectrum[a],i+=this._spectrum[a]}return i>0?t/i:0}}const audioEngine=new AudioEngine;!async function(){const e=["https://ethereum-rpc.publicnode.com","https://eth.drpc.org","https://0xrpc.io/eth","https://eth.llamarpc.com"],t=[79,162,778,991,1075,1238,1657,1669,2482,3005,3241,3348,3620,3829,3834,4338,4435,4473,4733,4875,4876,4975,5670,5769,6177,6201,6249,6825,7089,7177,7310,7360,8835,8929,9418,9721],i=[239,292,477,516,691,779,801,941,1126,1350,1386,1882,2599,2601,2650,2818,2841,2882,3113,3141,3317,3379,3511,3537,3625,3639,3936,4257,4318,4347,4593,4652,4835,4908,4941,4972,4986,4996,5075,5348,5380,5406,5456,5627,5885,6111,6786,6857,6891,6971,6981,7068,7074,7107,7203,7349,7406,7414,7492,7504,7711,7900,8305,8333,8341,8798,8806,8948,9100,9262,9358,9365,9441,9452,9616,9652,9673,9683,9735,9801,9852,9861,9902,9904,9984],a=[749,1787,1863,3138,3212,4962,5471,6239,6483,6570,6623,7238,7410,7709,8359,8435,8785,8838,9149,9376,9586,9694];var s=0;async function o(t){var i,a=await async function(t){var i=[{to:"0xECb92Cc7112b80A2234936315BbB493fb48d1463",data:t},"latest"];if(window.ethereum)try{var a=await window.ethereum.request({method:"eth_call",params:i});if(a&&"0x"!==a)return a}catch(e){}for(var o=0;o<e.length;o++){var r=(s+o)%e.length;try{var n=await fetch(e[r],{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",method:"eth_call",params:i,id:1})}),l=await n.json();if(l.result&&"0x"!==l.result)return s=r,l.result}catch(e){}}return null}("0xf5f770d6"+(i=t,i.toString(16).padStart(64,"0")));return a?parseInt(a,16):0}async function r(e){for(var t=[],i=0;i<e.length;i+=20){var a=e.slice(i,i+20).map(function(e){return o(e)}),s=await Promise.all(a);t=t.concat(s)}return t}function n(e){if(0===e.length)return 100;for(var t=0,i=0;i<e.length;i++)e[i]>0&&t++;return Math.round(t/e.length*100)}try{var l=await Promise.all([r(t),r(i),r(a)]),h=n(l[0]),d=n(l[1]),c=n(l[2]),u=STATE.layers.find(function(e){return"TemporalTunnel"===e.componentType});u&&(u.componentParams.redColorPercent=h,u.componentParams.greenColorPercent=d,u.componentParams.blueColorPercent=c),window._tunnelComponent&&(window._tunnelComponent.params.redColorPercent=h,window._tunnelComponent.params.greenColorPercent=d,window._tunnelComponent.params.blueColorPercent=c),console.log("[Chain] Color ratios — R:"+h+"% ("+l[0].filter(function(e){return e>0}).length+"/"+t.length+") G:"+d+"% ("+l[1].filter(function(e){return e>0}).length+"/"+i.length+") B:"+c+"% ("+l[2].filter(function(e){return e>0}).length+"/"+a.length+")")}catch(e){console.warn("[Chain] Color query failed, defaulting to 100%",e)}}();let layers=[],baseImage=null,baseLayerGraphics=null,aspectRatio=STATE.canvasSize.width/STATE.canvasSize.height;const originalWidth=STATE.canvasSize.width,originalHeight=STATE.canvasSize.height,renderEngine={outputBuffer:null};function preload(){STATE.baseLayer&&STATE.baseLayer.sourceUrl&&"image"===STATE.baseLayer.type&&(baseImage=loadImage(STATE.baseLayer.sourceUrl))}function calculateCanvasSize(){return{w:Math.floor(windowWidth),h:Math.floor(windowHeight)}}function setup(){console.log("[Composition] Setup starting..."),pixelDensity(1);const e=calculateCanvasSize();createCanvas(e.w,e.h),console.log("[Composition] Canvas created:",width,"x",height,"(pixelDensity: 1)"),loadingState.audio=!0,updateLoadStatus("audio","ok","tap to begin"),console.log("[Composition] Creating",STATE.layers.length,"layers..."),updateLoadStatus("images","pending","loading assets");const t=[];STATE.layers.forEach((e,i)=>{const a=window[e.componentType];if(a){console.log("[Composition] Creating layer",i,":",e.componentType);const s=new a(width,height,e.componentParams);if("TemporalTunnel"===e.componentType&&(window._tunnelComponent=s),"ImageLayer"===e.componentType&&e.componentParams.imageUrl){loadingState.imageCount++,console.log("[Composition] Loading image for layer",i,":",e.componentParams.imageUrl);const a=s.loadImage(e.componentParams.imageUrl).then(()=>{loadingState.imagesLoaded++,console.log("[Composition] Image loaded successfully for layer",i),updateLoadStatus("images","pending",loadingState.imagesLoaded+"/"+loadingState.imageCount)}).catch(e=>{loadingState.imagesLoaded++,console.error("[Composition] Failed to load image for layer",i,":",e)});t.push(a)}if("VideoLayer"===e.componentType&&e.componentParams.videoUrl){loadingState.imageCount++,console.log("[Composition] Loading video for layer",i,":",e.componentParams.videoUrl);const a=s.loadVideo(e.componentParams.videoUrl).then(()=>{loadingState.imagesLoaded++,console.log("[Composition] Video loaded successfully for layer",i),updateLoadStatus("images","pending",loadingState.imagesLoaded+"/"+loadingState.imageCount)}).catch(e=>{loadingState.imagesLoaded++,console.error("[Composition] Failed to load video for layer",i,":",e)});t.push(a)}const o=createGraphics(width,height);layers.push({component:s,...e,graphics:o})}else console.error("[Composition] Unknown component type:",e.componentType)}),STATE.baseLayer&&STATE.baseLayer.filters&&(baseLayerGraphics=createGraphics(width,height)),renderEngine.outputBuffer=createGraphics(width,height),0===t.length?(loadingState.images=!0,updateLoadStatus("images","ok")):Promise.all(t).then(()=>{loadingState.images=!0,updateLoadStatus("images","ok")}),loadingState.ready=!0,updateLoadStatus("ready","ok"),console.log("[Composition] Setup complete. Total layers:",layers.length)}function draw(){1===frameCount&&(console.log("[Composition] First draw() call. Layers:",layers.length),layers.forEach((e,t)=>console.log("[Composition] Layer",t,":",e.componentType,"visible:",e.visible))),audioEngine.analyze();const e=audioEngine.getSpectrum(),t=audioEngine.getWaveform(),i=audioEngine.getAllEnergy(),a=audioEngine.getAmplitude(),s=new Float32Array(t.length);for(let e=0;e<t.length;e++)s[e]=(t[e]-128)/128;const o=audioEngine.isBeat(),r={fftSpectrum:e,fftEnergy:i,amplitude:a,waveform:s,beatDetected:o,beat:o,centroid:audioEngine.getCentroid(),bass:i.bass||0,mid:i.mid||0,high:i.treble||0,mouseX:mouseX,mouseY:mouseY,pmouseX:pmouseX,pmouseY:pmouseY,mousePressed:mouseIsPressed,touches:[],mouseXNorm:mouseX/width,mouseYNorm:mouseY/height,time:millis()/1e3,deltaTime:deltaTime,frameCount:frameCount,fps:frameRate(),width:width,height:height,centerX:width/2,centerY:height/2,aspectRatio:width/height,minDim:min(width,height),maxDim:max(width,height)};if(background(STATE.backgroundColor||"#000000"),baseImage&&STATE.baseLayer&&STATE.baseLayer.visible){const e=baseImage.width/baseImage.height;let t,i,a,s;e>width/height?(i=height,t=height*e):(t=width,i=width/e),a=(width-t)/2,s=(height-i)/2;if(STATE.baseLayer.filters&&(STATE.baseLayer.filters.mainFilter||STATE.baseLayer.filters.processingFilters&&STATE.baseLayer.filters.processingFilters.length>0||STATE.baseLayer.filters.postFilters&&STATE.baseLayer.filters.postFilters.length>0||STATE.baseLayer.filters.shaderFilters&&STATE.baseLayer.filters.shaderFilters.length>0)&&baseLayerGraphics&&"undefined"!=typeof FilterRegistry){baseLayerGraphics.clear(),baseLayerGraphics.image(baseImage,a,s,t,i),applyLayerFilters(baseLayerGraphics,STATE.baseLayer.filters,r,deltaTime);const e=drawingCon