memoscan
← all memos

Memo 0x44113d2a…0c2d57 on Ethereum

urrentTime>.15&&(this._postWrapHoldUntil=0,1))),this._scratch=document.createElement("canvas"),this._scratchCtx=this._scratch.getContext("2d"),"function"==typeof e.requestVideoFrameCallback){this._useVfc=!0;const t=(i,a)=>{if(!this._video||this._video!==e)return;if(this._shouldHoldScratch&&this._shouldHoldScratch()){try{e.requestVideoFrameCallback(t)}catch(e){}return}const o=e.videoWidth,s=e.videoHeight;if(o>0&&s>0&&this._scratchCtx){this._scratch.width===o&&this._scratch.height===s||(this._scratch.width=o,this._scratch.height=s);try{this._scratchCtx.drawImage(e,0,0),this._hasCachedFrame=!0}catch(e){}}try{e.requestVideoFrameCallback(t)}catch(e){}};try{e.requestVideoFrameCallback(t)}catch(e){}}this._video=e}this._video.src=e;try{this._video.load()}catch(e){}}}update(e,t){}draw(e){if(this._loadFailed)return;const t=this._video;if(!t)return;const i=this.width,a=this.height,o=e.drawingContext,s=this._scratch,n=this._scratchCtx;if(this._hasCachedFrame&&s&&n&&o&&s.width>0&&s.height>0){const e=s.width,r=s.height,l=this._fit(i,a,e,r);if(!this._useVfc){const e=this._shouldHoldScratch&&this._shouldHoldScratch();if(!t.seeking&&t.readyState>=2&&!e&&t.videoWidth>0&&t.videoHeight>0){s.width===t.videoWidth&&s.height===t.videoHeight||(s.width=t.videoWidth,s.height=t.videoHeight);try{n.drawImage(t,0,0)}catch(e){}}}try{return void o.drawImage(s,l.dx,l.dy,l.dw,l.dh)}catch(e){}}if(t.readyState<2)return;const r=t.videoWidth,l=t.videoHeight;if(!r||!l)return;const h=this._fit(i,a,r,l);if(o)try{return void o.drawImage(t,h.dx,h.dy,h.dw,h.dh)}catch(e){}e.image(t,h.dx,h.dy,h.dw,h.dh)}_fit(e,t,i,a){if("stretch"===this.params.fit)return{dx:0,dy:0,dw:e,dh:t};const o=e/t,s=i/a;if("contain"===this.params.fit&&s>o||"cover"===this.params.fit&&s<o){const i=e/s;return{dx:0,dy:(t-i)/2,dw:e,dh:i}}const n=t*s;return{dx:(e-n)/2,dy:0,dw:n,dh:t}}resize(e,t){super.resize(e,t)}dispose(){if(null!=this._loopWatchId){try{cancelAnimationFrame(this._loopWatchId)}catch(e){}this._loopWatchId=null}if(this._video){try{this._video.pause()}catch(e){}try{this._video.removeAttribute("src"),this._video.load()}catch(e){}this._video.parentNode&&this._video.parentNode.removeChild(this._video),this._video=null}if(this._objectUrl&&"undefined"!=typeof URL){try{URL.revokeObjectURL(this._objectUrl)}catch(e){}this._objectUrl=null}this._scratch=null,this._scratchCtx=null,this._hasCachedFrame=!1}}class SpinningStar extends BaseComponent{static category="geometric";static isAudioReactive=!0;static displayName="Spinning Star";static description="Rotating star with audio-reactive points and radii";getDefaultParams(){return{numPoints:12,minPoints:6,maxPoints:64,outerRadiusFactor:1.5,innerRadiusFactor:.5,rotationSpeed:.005,pulseFactor:.05,colorHue:48,colorSaturation:24,colorBrightness:83,audioControlPoints:!0,audioControlOuter:!0,audioControlInner:!0,smoothing:.2,forceEvenPoints:!0,baseDiameter:.85}}getParameters(){return[{name:"numPoints",type:"range",min:3,max:128,step:1,label:"Base Points",hint:"Used when Audio Controls Points is off"},{name:"minPoints",type:"range",min:3,max:64,step:1,label:"Min Points",hint:"Requires Audio Controls Points enabled + audio playing"},{name:"maxPoints",type:"range",min:6,max:128,step:1,label:"Max Points",hint:"Requires Audio Controls Points enabled + audio playing"},{name:"outerRadiusFactor",type:"range",min:.5,max:3,step:.1,label:"Outer Radius",hint:"Modulated by audio when Audio Controls Outer is on"},{name:"innerRadiusFactor",type:"range",min:.01,max:1,step:.01,label:"Inner Radius",hint:"Modulated by audio when Audio Controls Inner is on"},{name:"rotationSpeed",type:"range",min:0,max:.05,step:.001,label:"Rotation Speed",hint:"Animates over time"},{name:"pulseFactor",type:"range",min:0,max:.2,step:.01,label:"Pulse Speed",hint:"Frequency of subtle size oscillation (0 = no pulse)"},{name:"colorHue",type:"range",min:0,max:360,step:1,label:"Hue"},{name:"colorSaturation",type:"range",min:0,max:100,step:1,label:"Saturation"},{name:"colorBrightness",type:"range",min:0,max:100,step:1,label:"Brightness"},{name:"audioControlPoints",type:"boolean",label:"Audio Controls Points",hint:"Mid frequencies control point count"},{name:"audioControlOuter",type:"boolean",label:"Audio Controls Outer",hint:"Amplitude controls outer radius"},{name:"audioControlInner",type:"boolean",label:"Audio Controls Inner",hint:"High frequencies control inner radius"},{name:"smoothing",type:"range",min:0,max:.5,step:.05,label:"Smoothing",hint:"Smooths transitions between audio-driven values"},{name:"forceEvenPoints",type:"boolean",label:"Force Even Points"},{name:"baseDiameter",type:"range",min:.3,max:1.5,step:.05,label:"Base Diameter"}]}constructor(e,t,i){super(e,t,i),this._rotation=0,this._frameCount=0,this._smoothedPoints=this.params.numPoints,this._smoothedOuter=this.params.outerRadiusFactor,this._smoothedInner=this.params.innerRadiusFactor}update(e,t){this._metrics=e,this._frameCount++;const i=this.params,a=void 0!==window._playbackDirection?window._playbackDirection:1;this._rotation+=i.rotationSpeed*a;const o=e&&void 0!==e.amplitude;let s,n,r;if(o&&i.audioControlPoints&&void 0!==e.mid){const t=Math.sin(.1*this._frameCount),a=(i.maxPoints-i.minPoints)/2,o=e.mid;s=i.numPoints+t*a*o,s=Math.max(i.minPoints,Math.min(i.maxPoints,s))}else s=i.numPoints;i.forceEvenPoints&&(s=2*Math.round(s/2)),this._smoothedPoints+=(s-this._smoothedPoints)*(1-i.smoothing),n=o&&i.audioControlOuter?i.outerRadiusFactor*(1+.5*e.amplitude):i.outerRadiusFactor,this._smoothedOuter+=(n-this._smoothedOuter)*(1-i.smoothing),r=o&&i.audioControlInner&&void 0!==e.high?i.innerRadiusFactor*(1+.5*e.high):i.innerRadiusFactor,this._smoothedInner+=(r-this._smoothedInner)*(1-i.smoothing)}draw(e){const t=this.params;e.push(),e.translate(this.width/2,this.height/2),e.rotate(this._rotation-e.HALF_PI),e.colorMode(e.HSB,360,100,100);const i=Math.min(this.width,this.height)*t.baseDiameter*e.map(Math.sin(this._frameCount*t.pulseFactor),-1,1,.95,1)/2;let a=i*this._smoothedOuter,o=i*this._smoothedInner;const s=Math.min(this.width,this.height)/2*.98;if(a>s){const e=s/a;a=s,o*=e}o>a&&(o=a),e.fill(t.colorHue,t.colorSaturation,t.colorBrightness),e.noStroke();let n=Math.round(this._smoothedPoints);t.forceEvenPoints&&(n=2*Math.round(n/2)),n=Math.max(3,n),this._drawStar(e,0,0,a,o,n),e.colorMode(e.RGB,255),e.pop()}_drawStar(e,t,i,a,o,s){const n=Math.max(3,Math.abs(s)),r=e.TWO_PI/n,l=r/2;e.beginShape();for(let s=0;s<e.TWO_PI;s+=r){let n=t+Math.cos(s)*a,r=i+Math.sin(s)*a;e.vertex(n,r),n=t+Math.cos(s+l)*o,r=i+Math.sin(s+l)*o,e.vertex(n,r)}e.endShape(e.CLOSE)}}class NoiseLayer extends BaseComponent{static category="shaders";static isAudioReactive=!0;static displayName="Noise";static description="Flowing organic noise patterns";constructor(e,t,i={}){super(e,t,i),this._time=0,this._shader=null,this._webglGraphics=null,this._lastWidth=0,this._lastHeight=0,this._metrics={amplitude:0,bass:0,mid:0,high:0,beat:!1}}getDefaultParams(){return{noiseType:"simplex",scale:3,speed:1,octaves:4,persistence:.5,lacunarity:2,colorMode:"rainbow",audioReactive:!0,audioScaleMult:1,audioSpeedMult:2}}getParameters(){return[{name:"noiseType",type:"select",label:"Noise Type",options:[{value:"simplex",label:"Simplex"},{value:"voronoi",label:"Voronoi"},{value:"worley",label:"Worley"}]},{name:"scale",type:"range",min:.5,max:10,step:.5,label:"Scale"},{name:"speed",type:"range",min:0,max:3,step:.1,label:"Speed"},{name:"octaves",type:"range",min:1,max:8,step:1,label:"Octaves"},{name:"persistence",type:"range",min:.1,max:1,step:.1,label:"Persistence"},{name:"lacunarity",type:"range",min:1,max:4,step:.1,label:"Lacunarity"},{name:"colorMode",type:"select",label:"Color Mode",options:[{value:"rainbow",label:"Rainbow"},{value:"fire",label:"Fire"},{value:"ocean",label:"Ocean"},{value:"grayscale",label:"Grayscale"}]},{name:"audioReactive",type:"boolean",label:"Audio Reactive"},{name:"audioScaleMult",type:"range",min:0,max:3,step:.1,label:"Audio Scale"},{name:"audioSpeedMult",type:"range",min:0,max:5,step:.1,label:"Audio Speed"}]}_getVertexShader(){return"\n attribute vec3 aPosition;\n attribute vec2 aTexCoord;\n varying vec2 vTexCoord;\n\n void main() {\n vTexCoord = aTexCoord;\n vec4 positionVec4 = vec4(aPosition, 1.0);\n positionVec4.xy = positionVec4.xy * 2.0 - 1.0;\n gl_Position = positionVec4;\n }\n "}_getFragmentShader(){return"\n precision highp float;\n\n uniform vec2 u_resolution;\n uniform float u_time;\n\n uniform float u_amplitude;\n uniform float u_bass;\n uniform float u_mid;\n uniform float u_high;\n uniform float u_beat;\n\n uniform int u_noiseType;\n uniform float u_scale;\n uniform float u_speed;\n uniform int u_octaves;\n uniform float u_persistence;\n uniform float u_lacunarity;\n uniform int u_colorMode;\n\n varying vec2 vTexCoord;\n\n vec2 hash2(vec2 p) {\n p = vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)));\n return -1.0 + 2.0 * fract(sin(p) * 43758.5453123);\n }\n\n vec3 hash3(vec2 p) {\n vec3 q = vec3(dot(p, vec2(127.1, 311.7)),\n dot(p, vec2(269.5, 183.3)),\n dot(p, vec2(419.2, 371.9)));\n return fract(sin(q) * 43758.5453);\n }\n\n float simplex(vec2 p) {\n vec2 i = floor(p);\n vec2 f = fract(p);\n vec2 u = f * f * (3.0 - 2.0 * f);\n\n return mix(\n mix(dot(hash2(i + vec2(0.0, 0.0)), f - vec2(0.0, 0.0)),\n dot(hash2(i + vec2(1.0, 0.0)), f - vec2(1.0, 0.0)), u.x),\n mix(dot(hash2(i + vec2(0.0, 1.0)), f - vec2(0.0, 1.0)),\n dot(hash2(i + vec2(1.0, 1.0)), f - vec2(1.0, 1.0)), u.x),\n u.y\n );\n }\n\n float voronoi(vec2 p) {\n vec2 i = floor(p);\n vec2 f = fract(p);\n float minDist = 1.0;\n\n for (int y = -1; y <= 1; y++) {\n for (int x = -1; x <= 1; x++) {\n vec2 neighb