memoscan
← all memos

Memo 0x7a119031…017d59 on Ethereum

const e=function(e){var t=/\(\s*([^)]+?)\s*\)/.exec(e.slice(e.indexOf("("),e.indexOf(")")+1));return t&&(t=t[1].split(/\s*,\s*/)),[...t||[],(e=e.slice(e.indexOf("{"),e.lastIndexOf("}")+1)).slice(1,e.length-1)]};p5.RendererGL.prototype._initContext=Function(...e(String(p5.RendererGL.prototype._initContext).replace("webgl","webgl2")));let t,r=p5.Texture.prototype;p5.Texture=function(e,t,r){this._renderer=e;const o=this._renderer.GL;r=r||{},this.src=t,this.glTex=void 0,this.glTarget=o.TEXTURE_2D,this.glFormat=r.format||o.RGBA,this.glInternalFormat=r.internalFormat||this.glFormat,this.mipmaps=!1,this.glMinFilter=r.minFilter||o.LINEAR,this.glMagFilter=r.magFilter||o.LINEAR,this.glDataType=r.dataType||o.UNSIGNED_BYTE,this.isSrcMediaElement=void 0!==p5.MediaElement&&t instanceof p5.MediaElement,this._videoPrevUpdateTime=0,this.isSrcP5Image=t instanceof p5.Image,this.isSrcP5Graphics=t instanceof p5.Graphics,this.isImageData="undefined"!=typeof ImageData&&t instanceof ImageData,this.isTexture=void 0!==t.texData;const i=this._getTextureDataFromSource();return this.width=i.width,this.height=i.height,this.init(i),this},p5.Texture.prototype=r,p5.Texture.prototype.init=function(e){const t=this._renderer.GL;this.glTex=t.createTexture(),this.glWrapS=this._renderer.textureWrapX,this.glWrapT=this._renderer.textureWrapY,this.setWrapMode(this.glWrapS,this.glWrapT),this.bindTexture(),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,this.glMagFilter),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,this.glMinFilter),t.texImage2D(this.glTarget,0,this.glInternalFormat,this.width,this.height,0,this.glFormat,this.glDataType,e.texData)},p5.Texture.prototype._getTextureDataFromSource=function(){let e;return e=this.isSrcP5Image?this.src.canvas:this.isSrcMediaElement||this.isSrcP5Graphics||this.isSrcHTMLElement?this.src.elt:this.src,e},p5.Texture.prototype.update=function(){const e=this.src,t=this._getTextureDataFromSource(),r=this._renderer.GL;return this.bindTexture(),this.isTexture?r.texImage2D(this.glTarget,0,this.glInternalFormat,this.width,this.height,0,this.glFormat,this.glDataType,e.texData):r.texImage2D(this.glTarget,0,this.glFormat,this.glFormat,this.glDataType,t),!0},p5.Shader.prototype.oldProtoSetUniform=p5.Shader.prototype.setUniform,p5.Shader.prototype.setUniform=function(e,t){this.oldProtoSetUniform(e,t);const r=this.uniforms[e];if(!r)return;const o=this._renderer.GL,i=r.location;switch(this.useProgram(),r.type){case o.SAMPLER_2D:case o.UNSIGNED_INT_SAMPLER_2D:o.activeTexture(o.TEXTURE0+r.samplerIndex),r.texture=t instanceof p5.Texture?t:this._renderer.getTexture(t),o.uniform1i(i,r.samplerIndex)}return this},p5.Shader.prototype._loadUniforms=Function(...e(String(p5.Shader.prototype._loadUniforms).replace("o.type===e.SAMPLER_2D","(o.type===e.SAMPLER_2D||o.type===e.UNSIGNED_INT_SAMPLER_2D)"))),p5.Vector.normalize=function(e,t){return arguments.length<2?t=e.copy():t.set(e),t.normalize()};class o{constructor(e){this.useA=!1;let t=function(e){let t=parseInt(e.substr(0,8),16),r=parseInt(e.substr(8,8),16),o=parseInt(e.substr(16,8),16),i=parseInt(e.substr(24,8),16);return function(){t|=0,r|=0,o|=0,i|=0;let e=(t+r|0)+i|0;return i=i+1|0,t=r^r>>>9,r=o+(o<<3)|0,o=o<<21|o>>>11,o=o+e|0,(e>>>0)/4294967296}};this.prngA=new t(e.hash.substr(2,32)),this.prngB=new t(e.hash.substr(34,32));for(let e=0;e<1e6;e+=2)this.prngA(),this.prngB()}random_dec(){return this.useA=!this.useA,this.useA?this.prngA():this.prngB()}}const i=()=>{t=new o(tokenData)};i(),p5.prototype.random=function(e,r){const o=t.random_dec();if(void 0===e)return o;if(void 0===r)return e instanceof Array?e[Math.floor(o*e.length)]:o*e;if(e>r){var i=e;e=r,r=i}return o*(r-e)+e},p5.prototype.shuffle=function(e,t){const r=ArrayBuffer&&ArrayBuffer.isView&&ArrayBuffer.isView(e);let o,i,a=(e=t||r?e:e.slice()).length;for(;a>1;)o=this.random(0,1)*a|0,i=e[--a],e[a]=e[o],e[o]=i;return e};const a={arrToObj:e=>e.reduce(((e,t)=>(e[t[0]]=t[1],e)),{}),cumSum(e){let t=new Array(e.length);return e.reduce(((e,r,o)=>t[o]=e+r),0),t},range(e,t,r){if(0===e&&0===t)return[];const o=t-e,i=Math.ceil(o/r)+1;return[...new Array(i)].map(((o,i)=>Math.min(t,e+i*r)))},download(e,t,r){var o=new Blob([e],{type:r});if(window.navigator.msSaveOrOpenBlob)window.navigator.msSaveOrOpenBlob(o,t);else{var i=document.createElement("a"),a=URL.createObjectURL(o);i.href=a,i.download=t,document.body.appendChild(i),i.click(),setTimeout((function(){document.body.removeChild(i),window.URL.revokeObjectURL(a)}),0)}},camelCaseToText(e){const t=e.replace(/([A-Z])/g," $1");return t.charAt(0).toUpperCase()+t.slice(1)},steps:(e,t,r)=>Math.floor(e*t)/t+(r?1/t:0)};class n{config={};constructor(e){this.env=e}_addProp(e,t){this.config[e]={val:this.getWithin(t,"val"),pub:t.pub,...t.name?{name:this.getWithin(t,"name")}:{}}}addPropWPub(e,t,r){this._addProp(e,{...t.name?t:{val:t},pub:r})}addPrivProp(e,t){this.addPropWPub(e,t,!1)}addProp(e,t){this.addPropWPub(e,t,!0)}getConfig(e){return a.arrToObj(Object.entries(this.config).filter((([,t])=>t.pub==e)).map((([t,r])=>[r.name?r.name:e?a.camelCaseToText(t):t,(()=>{const t=void 0!==r.val?r.val:r;return e&&"string"==typeof t?a.camelCaseToText(t):t})()])))}get priv(){return this.getConfig(!1)}get pub(){return this.getConfig(!0)}getWithin(e,t="val"){return void 0!==e[t]?e[t]:e}getProp(e){return this.config[e]?this.config[e].val:this.config[e]}}class s{constructor(...e){const t=e[0];for(let r=1;r<e.length;r++)e[r]=t.createGraphics(t.width,t.height);e.push(t.createGraphics(t.width,t.height)),this.layers=e,this.main=e[e.length-1]}pgsFn(e,t){for(let r of this.layers)r[e](...t)}get p(){return this.layers[0]}}class l{memo={};loading=!1;postInited=!1;get p(){return this.layers.p}get mainLayer(){return this.layers.main}constructor(e,t,r,o,i,a=1,n=1080){this.addCSSStyles(),this.layers=new s(...e);const l=Object.fromEntries(new URLSearchParams(window.location.search).entries());this.scaleFactor=l.scaleFactor?Number(l.scaleFactor):a,this.initScaleFactor=this.scaleFactor,this.env=t,this.collection=o??"",this.baseDim=n,this.configInit=i,this.init(r),this.p.windowResized=()=>{this.canvasCssDim()},this.p.keyPressed=()=>{switch(this.p.keyCode){case 85:case 74:{const e=this.scaleFactor;if(85===this.p.keyCode?this.scaleFactor+=.25:74===this.p.keyCode&&(this.scaleFactor-=.25),this.scaleFactor=Math.max(this.scaleFactor,.75),e===this.scaleFactor)return;this.reset(),this.canvasCssDim(),console.log("SCALE_FACTOR:",this.scaleFactor),console.log(`width: ${this.dim}px`,`height: ${this.dim}px`);break}case 83:this.loading||this.saveOutput()}}}reset(){this.init(this.CONFIG.getProp("artName"),!1),this.p.redraw()}init(e=tokenData.hash,t=!0){tokenData.hash=e,this.drawer=void 0,this.setRandShader(),this.dim=this.baseDim*this.scaleFactor,this.p.drawingContext?(this.layers.pgsFn("resizeCanvas",[this.dim,this.dim,!0]),this.memo.combineTex&&this.memo.combineTex.resizeCanvas(this.dim,this.dim)):this.p.createCanvas(this.dim,this.dim),this.layers.pgsFn("pixelDensity",[1]),this.canvasCssDim(),!t&&this.CONFIG||(this.CONFIG=new n(this.env),this.CONFIG.addPrivProp("artName",e),this.CONFIG.addPrivProp("tokenData",tokenData),this.resetSeed(),this.configInit(this),this.print()),this.resetSeed(),document.title=`${this.collection}: ${this.CONFIG.getProp("artName")}`,this.start=Date.now(),this.loading=!1}timeElapsed(){return(Date.now()-this.start)/1e3}printTimeElapse(){console.log("generated in:",this.timeElapsed())}resetSeed(){i(),this.layers.pgsFn("noiseSeed",[this.getSeed()]),this.layers.pgsFn("randomSeed",[this.getSeed()])}weightedRandom(e,t){const r=this.p.random(),o=[...t].map(((e,t)=>[e,t]));let i=0;o.sort(((e,t)=>e[0]-t[0]));const n=a.cumSum(o.map((e=>e[0])));for(let t of n){if(r<t)return e[o[i][1]];i++}return e[o[o.length-1][1]]}luma=e=>{this.p.colorMode(this.p.RGB);const t=this.p.createVector(this.p.red(e)/255,this.p.green(e)/255,this.p.blue(e)/255);return p5.Vector.dot(t,this.p.createVector(.299,.587,.114))};createPostProcTexGL(){void 0===this.memo.combineTex&&(this.memo.combineTex=this.p.createGraphics(this.p.width,this.p.height,this.p.WEBGL))}getShaderSeed(){return 500*(this.getSeed()/Math.pow(10,String(this.getSeed()).length))}setRandShader(){this.memo.randTex&&(this.memo.randTex.shader(this.memo.randShader),this.memo.randShader.setUniform("seed",this.getShaderSeed()),this.memo.randTex.rect(0,0,this.memo.randTex.width,this.memo.randTex.height))}endFrame(){this.postInited=!1,this.memo.combineTex?this.p.image(this.memo.combineTex,0,0,this.p.width,this.p.height):this.p.image(this.mainLayer,0,0,this.p.width,this.p.height)}initPost(){this.createPostProcTexGL(),this.createPostProcShaderGL(),this.postInited||(this.postInited=!0,this.drawPost("","outColor = vec4(vec3(tex.rgb), 1.);",(()=>({})),"copy",this.mainLayer))}drawGrainGL(e=.5){this.initPost();const t=this.memo.combineTex;if(void 0===this.memo.randTex){const e=Math.pow(2,11);this.memo.randTex=this.p.createGraphics(e,e,this.p.WEBGL);const r=`#version 300 es\nprecision highp float;uniform float seed;in vec2 vTexCoord;out vec4 outColor;${d}void main() {vec2 uv = vTexCoord;float randVal = rand(seed + uv * rand(uv));outColor = vec4(vec3(randVal), 1.0 );}`;this.memo.randShader=this.memo.randTex.createShader(c,r),this.memo.combineRandShader=t.createShader(c,"#version 300 es\nprecision highp float;in vec2 vTexCoord;out vec4 outColor;uniform sampler2D randTex;uniform sampler2D tex0;uniform float scaleFactor;uniform float grainIntensity;void main() {vec2 uv = vTexCoord;uv.y = 1.0 - uv.y;float randVal = texture(randTex, uv).r;vec4 tex = texture(tex0, uv);outColor = vec4(tex.rgb + vec3((randVal * 2. - 1.) * grainIntensity), 1.0 );}"),this.setRandShader()}const r=this.memo.randTex,o=this.memo.combineRandShader;t.shader(o),o.setUniform("tex0",t),o.setUniform("scaleFactor",this.scaleFactor/this.initScaleFactor),o.setUniform("randTex",r),o.setUniform("grainIntensity",e),t.rect(0,0,t.width,t.height)}createPostProcShaderGL(){this.memo.postShader||(this.memo.postShader={})}drawPost(e="",t="",r,o="def",i,a=!0,n=!0){this.initPost();const s=this.memo.combineTex;void 0===this.memo.postShader[o]&&(this.memo.postShader[o]={},this.memo.postShader[o].shader=s.createShader(c,`#version 300 es\nprecision highp float;precision lowp usampler2D;float PI = 3.